Created
July 20, 2022 10:43
-
-
Save dubeyji10/4db716150ad451eb57d368fe7f0efaeb to your computer and use it in GitHub Desktop.
Querying data in mongodb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MongoDB Playground | |
// To disable this template go to Settings | MongoDB | Use Default Template For Playground. | |
// Make sure you are connected to enable completions and to be able to run a playground. | |
// Use Ctrl+Space inside a snippet or a string literal to trigger completions. | |
// Select the database to use. | |
use('landTestV2'); | |
// The drop() command destroys all data from a collection. | |
// Make sure you run it against the correct database and collection. | |
// Insert a few documents into the sales collection. | |
// Run a find command to view items sold on April 4th, 2014. | |
// db.landTestV2.find(); | |
// find records with date = 1967-07-13 -- 3 records | |
// db.landTestV2.find({'date':new Date('1967-07-13')}) | |
// find records with date != 1967-07-13 -- 98 records | |
//db.landTestV2.find({'date':{'$ne':new Date('1967-07-13')}}) | |
// count | |
// db.landTestV2.find({'date':{'$ne':new Date('1967-07-13')}}).count() | |
// find records with date equals = 1934-05-09 or 1967-07-13 | |
// db.landTestV2.find({'date':{'$in':[new Date('1967-07-13'),new Date('1934-05-09')]}}) | |
// OR operator multiple conditions | |
// using or query land with date = '1967-07-13' or date = '1934-05-09' | |
// use or operator | |
//db.landTestV2.find({'$or':[{'date':new Date('1967-07-13')},{'date':new Date('1934-05-09')}]}) | |
// HONEGGER Madeleine Heather | |
// this should also give 5 items this is or equivalent of above in example | |
// db.landTestV2.find({'owner':'HONEGGER Madeleine Heather'}) | |
//db.landTestV2.find({'owner':{'$in':['ETAT DE GENEVE','HONEGGER Madeleine Heather']}}) | |
// skeleton for or operation | |
// db.landTestV2.find({'$or':[]}) | |
// either fullfill owner condition or the owner condition | |
db.landTestV2.find({'$or':[{'owner':{'$in':['ETAT DE GENEVE','HONEGGER Madeleine Heather']}}, | |
{'date':{'$in':[new Date('1967-07-13'),new Date('1934-05-09')]}}]}) | |
// | |
// owner -db.landTestV2.unique(..... field .....) {} | |
// bno -db.landTestV2.unique(..... field .....) {} | |
// date -db.landTestV2.unique(..... field .....) {} | |
// address -db.landTestV2.unique(..... field .....) {} | |
// {'owners':[] ,'date':[],'address':[],'bno':[]} | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment