0

Recently I'm learning MongoDB and Python by myself and I encounter this problem.

https://i.sstatic.net/acQxl.png

enter image description here

For object 1-3 there is date information in it but some object does not contain date on it. How can I remove the object that doesn't contain date in it by using MongoDB and Python script?Thanks in advance.

1
  • 2
    "Remove missing data" is contradictory. Either you have data which you like to remove or the data is missing. Please don't paste images, provide documents as formatted text, see meta.stackoverflow.com/a/285557/3027266 Commented Jan 31, 2021 at 12:56

2 Answers 2

1

just try

update(
{} ,
{ "$pull": { data :{ date: { "$exists":  false } }} },
false,true)
Sign up to request clarification or add additional context in comments.

3 Comments

This command is not working in my MongoDB..it popout unknown expression $exists
If you use with double cotatiob or without $ whats happend?
I manage to get it run on my MongoDB.thanks.Is this the same way to do in Python 3?
0

Use $pull to remove items from the array.

$pull

Find part of update: Use $exists on date field to check the existence.

db.coll.update({},
{
  "$pull": {
    "arr": {
      "a": {
        exists: false
      }
    }
  }
})

2 Comments

I thought of using $pull but I thought pull is for existing data.Can you show me the command for my question above?Thanks
db.coll.update({}, { "$pull": { "arr": { "a": { exists: false } } } }) Please try this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.