top of page
Search
Writer's pictureKiazsoft

MongoDB

Updated: Jan 21, 2022

Mongo Sample find query

db.getCollection("user").find(
    {
        "username" : "kia"
    },
    {//projections
        "username": 1.0, //1.0 means include
        "address": 1.0,
        "phone": 1.0
    }
).sort(
    {
        "createDate": -1.0 //-1.0 is descending order
    }
);

Aggregate query


db.getCollection("collectionName").aggregate([
    {"$match": { "col1":"colValue", "date": {
                   "$gte": ISODate("2021-01-01T00:00.000+0000"),  
                   "$gte": ISODate("2021-01-02T00:00.000+0000")       
                   }
                }
    },
    {"$group": {"_id":"colId", "count": {"$sum":1}}}

]);


7 views0 comments

Recent Posts

See All

Mac Useful Commands

Show hidden files in Finder Command + Shift + .

Git

Removing file from all history. git filter-branch --force --index-filter \ "git rm --cached --ignore-unmatch PATH-TO-FILE" \...

Expo for React Native

Install expo-cli. If on Mac you get any permission errors then run as sudo npm install expo-cli --global Create expo project expo init...

Comments


bottom of page