4

Within my mongo collection, I have a nested variable of called "institution.type". This is an array with the following elements:

db.collection.distinct("institution.type") 
[
null,
[
    "boarding"
],
"virtual"
]

I am trying to remove the entries with the "boarding" element, however am getting stuck due to the fact that boarding itself is within an array ( a mistake initially made when using "$push" to an array)

I have tried the following to find the documents:

db.collection.find({"institution.type":{ $in: ["boarding"]}}).count()
0

and

db.collection.update({"institution.id":"somenumber"}, {$pull:   {"institution.type.1":"boarding"}})
"type" : [
        "virtual",
        [ ]
         ]

How can I remove the brackets along with the "boarding" tag without getting the error of

JavaScript execution failed: SyntaxError: Unexpected identifier ?

Any advice would be greatly appreciated and welcomed!

1 Answer 1

1

To find the item with the boarding subarray you have to use double brackets like so...

db.collection.find({"institution.type": {$in: [["boarding"]]}})

To pull the item out do the following:

db.collection.update({"institution.type": {$in: [["boarding"]]}}, {$pull: {"institution.type": ["boarding"]}})
Sign up to request clarification or add additional context in comments.

Comments

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.