Thursday, November 9, 2017

MongoDB Search Collections

Document:
{
    "_id" : ObjectId("5a046e1151c456a18a6146f5"),
    "name" : [ 
        "bmw", 
        "bav motor wagen"
    ],
    "class" : {
        "usa" : "suv",
        "europe" : "compact"
    },
    "speed" : [ 
        {"mph" : 100}, 
        {"kph" : 120}
    ]
}
search query width and criteria, array match, object match
db.getCollection('cars').find({
    "name":"bmw",
    "class.usa": "suv",
    $and :[ 
        {"speed.0.mph": { $eq:100 }}, 
        {"speed.1.kph": { $eq:120 }} 
   ]
}
)

No comments:

Post a Comment