Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (50.2k points)

I am attempting to use the following query in MongoDB shell but it is not working.

db.test.aggergate(

$match: {$and: [type: {$in: ["TOYS"]}, type: {$nin: ["BARBIE"]}, time: 

{$lt:ISODate("2013-12-09T00:00:00Z")}]}})

The error is showing that ":" is an invalid character.

Can we use $and with $match?

1 Answer

0 votes
by (107k points)
edited by

There is a syntax error in your query. Try the following code:

db.test.aggregate([

                   { 

                     $match: {

                          $and: [ 

                              {type: {$in: ["TOYS"]}}, 

                              {type: {$nin: ["BARBIE"]}}, 

                              {time: {$lt:ISODate("2013-12-09T00:00:00Z")}}

                          ]

                     }

                   }

                  ])

If you are a beginner and want to know more about MongoDB then refer to the following MongoDB tutorial which will help you to learn MongoDB from scratch.

Learn about full stack web development by signing up for this professional Full Stack Training offered by Intellipaat..

Related questions

0 votes
1 answer
asked Feb 13, 2020 in Web Technology by ashely (50.2k points)
0 votes
1 answer
asked Feb 7, 2020 in Web Technology by ashely (50.2k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...