use uber db.createCollection("uber"); db.uber.insert({ "Request id": "619", "Pickuppoint": "Airport", "Driverid": "1", "Status": "Trip Completed", "Request timestamp": "11/7/2016 11:51", "Drop timestamp": "11/7/2016 13:00" }); db.uber.insert({ "Request id": "267", "Pickuppoint": "City", "Driverid": "2", "Status": "Trip Completed", "Request timestamp": "11/7/2016 6:46", "Drop timestamp": "11/7/2016 7:25" }); db.uber.insert({ "Request id": "535", "Pickuppoint": "Airport", "Driverid": "3", "Status": "Trip Completed", "Request timestamp": "11/7/2016 10:00", "Drop timestamp": "11/7/2016 10:31" }); db.uber.insert({ "Request id": "3722", "Pickuppoint": "Airport", "Driverid": "4", "Status": "Trip Completed", "Request timestamp": "13-07-2016 19:57:59", "Drop timestamp": "13-07-2016 20:32:04" }); db.uber.insert({ "Request id": "1756", "Pickuppoint": "Airport", "Driverid": "5", "Status": "Trip Completed", "Request timestamp": "12/7/2016 8:40", "Drop timestamp": "12/7/2016 9:23" }); db.uber.insert({ "Request id": "5741", "Pickuppoint": "City", "Driverid": "6", "Status": "Trip Completed", "Request timestamp": "15-07-2016 07:52:51", "Drop timestamp": "15-07-2016 08:38:55" }); db.uber.remove({Driverid:'6'}); db.uber.find();
Write, Run & Share MongoDB queries online using OneCompiler's MongoDB online editor and compiler for free. It's one of the robust, feature-rich online editor and compiler for MongoDB. Getting started with the OneCompiler's MongoDB editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'MongoDB' and start writing queries to learn and test online without worrying about tedious process of installation.
MongoDB is a cross platform document oriented NoSQL database.
db.collection.insert()
: Using insert
you can either insert one document or array of documentsdb.employees.insert( {empId: 3, name: 'Ava', dept: 'Sales' });
db.collection.insertOne()
: Inserts one documentdb.employees.insertOne( {empId: 4, name: 'Nick', dept: 'Accounting' });
db.collection.insertMany
: Inserts multiple documentsdb.employees.insertMany([
{empId: 1, name: 'Clark', dept: 'Sales' },
{empId: 2, name: 'Dave', dept: 'Accounting' }
]);
db.collection.update()
: Updates one or more than one document(s) in collection based on matching document and based on multi
optiondb.employees.update(
{empId: 3 },
{ $set: { region: "Asia" } }
);
db.collection.updateOne()
: Updates a single document in collection based on matching documentdb.employees.updateOne(
{empId: 2 },
{ $set: { region: "Asia" } }
);
db.collection.updateMany()
: Updates multiple documents in collection based on the condition.db.employees.updateMany(
{ dept: 'Sales'},
{ $set: { region: "US" } }
);
db.collection.deleteOne(<filter>, <options>)
: Deletes a Single document from collectiondb.employees.deleteOne({ empId: 1})
db.collection.deleteMany(<filter>, <options>)
: Deletes all documents with matching filterdb.employees.deleteMany({ dept: 'Sales'})