0

I have table of item list (like image). Now I wanna find a object that have name contain searchString.
I tried query like db.getCollection('vehicles').find({'result': {'name': 'A-WING FIGHTER'}}) but it look wrong.
How can I get true data in this case?

enter image description here

3 Answers 3

1

by this

db.getCollection('vehicles').find({ 'result': { 'name': 'A-WING FIGHTER' } })

you are searching for an exact match, so result must be an object with property name only

you should use the dot notation instead

db.getCollection('vehicles').find({ 'results.name': 'A-WING FIGHTER' })

hope it helps

Sign up to request clarification or add additional context in comments.

Comments

0

See if the following command works -

db.getCollection('vehicles').find({'results': {'name': 'A-WING FIGHTER'}})

You named result instead of results. Try if it works now...

You can also try using the following code snippet -

db.getCollection('vehicles').find({ results.name: 'A-WING FIGHTER' });

1 Comment

Also, db.getCollection('vehicles').find({'results': 'A-WING FIGHTER'}) should also work as well if I am not mistaken.
0

To search the array of array in MongoDB, you can use $elemMatch operator.

Try this query (This query is according to the image you shared)

db.getCollection('items').find({'results': {'$elemMatch: {'$elemMatch: {'name': 'A-WING FIGHTER'}}}})

Hope this will be helpfull.

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.