use novia
db.product_catalog.insertMany([{prodid:7000001,prodname:"iphone 7",manufacturer:"apple",categories:{main:"electronics",sub:"smartphones"},date_of_launch:{$date:"2016-09-07T00:00:00Z"},price:60000,colors:["silver","black","gold","rosegold"],spec_length_mm:138.3,spec_width_mm:67.1,spec_thickness_mm:7.1,spec_weight_g:138,spec_rear_cam_megapixel:12,spec_front_cam_megapixel:7,description:"12MP primary camera, Quad-LED True Tone flash and Live Photos, 4K video recording, 7MP front facing FaceTime HD camera with Retina.It's water and dust resistant iOS 10 and iCloud operating system, 2GB RAM and single Nano-SIM Non-removable Li-Ion 1960 mAh battery"},
{prodid:7000002,prodname:"galaxy 7",manufacturer:"samsung",categories:{main:"electronics",sub:"smartphones"},date_of_launch:{$date:"2016-07-07T00:00:00Z"},price:45000,colors:["white","black","gold"],spec_length_mm:140,spec_width_mm:70,spec_thickness_mm:8,spec_weight_g:140,spec_rear_cam_megapixel:16,spec_front_cam_megapixel:12,description:"Incredible communication experience. The dual SIM galaxy mobile runs on Quad-core Kryo processor and is based on Marshmallow Android 6.0 OS . Storage and memory needs are met through 4GB RAM and built-in storage of 32GB with an extendable option upto 200GB via microSD slot. Backed by 3600mAh battery, has 5MP front camera for selfie fun"},
{prodid:7000003,prodname:"nexus 7",manufacturer:"google",categories:{main:"electronics",sub:"smartphones"},date_of_launch:{$date:"2016-07-08T00:00:00Z"},price:30000,colors:["white","black"],spec_length_mm:130,spec_width_mm:65,spec_thickness_mm:9,spec_weight_g:150,spec_rear_cam_megapixel:12,spec_front_cam_megapixel:7, description:"An exquisite frame for your life,The octa-core Qualcomm Snapdragon 810 v2.1 processor and 3450 mAh battery will keep you talking, texting, and apping at top speeds, into the night"},
{prodid:7000004,prodname:"lyf7",manufacturer:"google",categories:{main:"electronics",sub:"smartphones"},date_of_launch:{$date:"2015-11-17T00:00:00Z"},price:20000,colors:["white","black"],spec_length_mm:125,spec_width_mm:57,spec_thickness_mm:7,spec_weight_g:120,spec_rear_cam_megapixel:16,spec_front_cam_megapixel:7, description:"Display: 5 inch HD IPS Screen, Rear Camera : 8 Megapixels with Flash, Front Camera : 5 Megapixels Processor (CPU): Quad-Core 1.3 ,Battery Capacity: 2250 mAh, DUAL SIM, OS: Android 6 Marshmallow Internal Memory: 16 GB,2 Years LYF Warranty LYF WIND 7S has a compact build for easy one hand operations"},
{prodid:7000005,prodname:"xperia z",manufacturer:"sony",categories:{main:"electronics",sub:"smartphones"},date_of_launch:{$date:"2014-10-19T00:00:00Z"},price:35000,colors:["silver","black"],spec_length_mm:129,spec_width_mm:58,spec_thickness_mm:8.1,spec_weight_g:130,spec_rear_cam_megapixel:12,spec_front_cam_megapixel:5, description:"The Sony Xperia T2 Ultra features a 6-inch 720p HD TRILUMINOS display that provides razor sharp picture clarity.Adding smart features to the Sony Xperia T2 display is the Mobile Bravia Engine 2"},
{prodid:7000006,prodname:"zenfone 3",manufacturer:"asus",categories:{main:"electronics",sub:"smartphones"},date_of_launch:{$date:"2014-08-29T00:00:00Z"},price:15000,colors:["silver","black"],spec_length_mm:134,spec_width_mm:62,spec_thickness_mm:7.6,spec_weight_g:145,spec_rear_cam_megapixel:12,spec_front_cam_megapixel:5,description:"Zenfone 3 has exquisite design. A glass and metal wonder that captures the world with absolute clarity"},
{prodid:7000007,prodname:"lg g7",manufacturer:"LG",categories:{main:"electronics",sub:"smartphones"},date_of_launch:{$date:"2014-08-30T00:00:00Z"},price:40000,colors:["silver","white","black"],spec_length_mm:136,spec_width_mm:64,spec_thickness_mm:7.4,spec_weight_g:135,spec_rear_cam_megapixel:16,spec_front_cam_megapixel:5},
{prodid:7000008,prodname:"coolpad 7",manufacturer:"coolpad",categories:{main:"electronics",sub:"smartphones"},date_of_launch:{$date:"2016-07-10T00:00:00Z"},price:12000,colors:["silver","gold","black"],spec_length_mm:137,spec_width_mm:67,spec_thickness_mm:7.8,spec_weight_g:157,spec_rear_cam_megapixel:12,spec_front_cam_megapixel:7},
{prodid:7000009,prodname:"gionee s6",manufacturer:"gionee",categories:{main:"electronics",sub:"smartphones"},date_of_launch:{$date:"2016-09-09T00:00:00Z"},price:17000,colors:["silver","white","gold"],spec_length_mm:135,spec_width_mm:29,spec_thickness_mm:8.3,spec_weight_g:168,spec_rear_cam_megapixel:12,spec_front_cam_megapixel:12},
{prodid:7000010,prodname:"nosql distilled",publisher:"Addison-Wesley",authors:["pramod sadalage","martin folwer"],ISBN:1234567,categories:{main:"books",sub:"technical"},date_of_publishing:{$date:"2012-12-12T00:00:00Z"},price:400,revisedYears:[2015,2016,2017]},
{prodid:7000011,prodname:"big data: principles and best practices",publisher:"Dreamtech",authors:["james warren","nathan marz"],ISBN:2323232,categories:{main:"books",sub:"technical"},date_of_publishing:{$date:"2015-05-27T00:00:00Z"},price:700,revisedYears:[2011,2015,2016]},
{prodid:7000012,prodname:"hadoop application architectures",publisher:"Shroff",authors:["martin grover"],ISBN:1979891,categories:{main:"books",sub:"technical"},date_of_publishing:{$date:"2015-01-01T00:00:00Z"},price:600,revisedYears:[2011,2015]},
{prodid:7000013,prodname:"learning spark",publisher:"O'Reilly",authors:["holden karau","andy konwinski"],ISBN:2343454,categories:{main:"books",sub:"technical"},date_of_publishing:{$date:"2015-01-01T00:00:00Z"},price:500,revisedYears:[2010,2011]},
{prodid:7000014,prodname:"formal men shoes",manufacturer:"bata",categories:{main:"shoes",gender:"men",sub:"formal"},price:3000,colors:["black","brown"]},
{prodid:7000015,prodname:"casual men shoes",manufacturer:"nike",categories:{main:"shoes",gender:"men",sub:"casual"},price:2500,colors:["brown","blue"]},
{prodid:7000016,prodname:"tennis men shoes",manufacturer:"nike",categories:{main:"shoes",gender:"men",sub:{sub:"sports",type:"tennis"}},price:3000,colors:["blue","white","black"]},
{prodid:7000017,prodname:"casual women shoes",manufacturer:"puma",categories:{main:"shoes",gender:"women",sub:"casual"},price:2000,colors:["white","black","red"]},
{prodid:7000018,prodname:"tennis women shoes",manufacturer:"reebok",categories:{main:"shoes",gender:"women",sub:{sub:"sports",type:"tennis"}},price:3300,colors:["white","black","red"]},
{prodid:7000019,prodname:"washing machine - front load - ifb",manufacturer:"IFB",categories:{main:"electronics",sub:"washing machine"},price:30000,colors:["silver","white"]},
{prodid:7000020,prodname:"washing machine - top load - ifb",manufacturer:"IFB",categories:{main:"electronics",sub:"washing machine"},price:29000,colors:["silver","white"]},
{prodid:7000021,prodname:"washing machine - front load - whirlpool",manufacturer:"whirlpool",categories:{main:"electronics",sub:"washing machine"},price:32000,colors:["silver","white"]},
{prodid:7000022,prodname:"washing machine - top load - whirlpool",manufacturer:"whirlpool",categories:{main:"electronics",sub:"washing machine"},price:27000,colors:["silver","white"]}])
db.product_catalog.find({$and:[{prodname:"nexus 7"},{price:{$lte:30000}}]})
 

MongoDB online editor

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.

About MongoDB

MongoDB is a cross platform document oriented NoSQL database.

Key Features:

  • Designed to overcome the the limitations of relational databases approach and other NoSQL solutions
  • Horizontal scaling
  • Load balancing capabilities
  • Better data availability and stability

Syntax help

Commands

Inserting documents

  1. db.collection.insert(): Using insert you can either insert one document or array of documents
db.employees.insert(   {empId: 3, name: 'Ava', dept: 'Sales' });
  1. db.collection.insertOne(): Inserts one document
db.employees.insertOne(  {empId: 4, name: 'Nick', dept: 'Accounting' });
  1. db.collection.insertMany: Inserts multiple documents
db.employees.insertMany([
  {empId: 1, name: 'Clark', dept: 'Sales' },
  {empId: 2, name: 'Dave', dept: 'Accounting' }
]);

Updating documents

  1. db.collection.update() : Updates one or more than one document(s) in collection based on matching document and based on multi option
db.employees.update(   
  {empId: 3 },
  { $set: { region: "Asia" } }
);
  1. db.collection.updateOne() : Updates a single document in collection based on matching document
db.employees.updateOne(   
  {empId: 2 },
  { $set: { region: "Asia" } }
);
  1. db.collection.updateMany() : Updates multiple documents in collection based on the condition.
db.employees.updateMany(   
  { dept: 'Sales'},
  { $set: { region: "US" } }
);

Deleting documents

  1. db.collection.deleteOne(<filter>, <options>): Deletes a Single document from collection
db.employees.deleteOne({ empId: 1})
  1. db.collection.deleteMany(<filter>, <options>): Deletes all documents with matching filter
db.employees.deleteMany({ dept: 'Sales'})