MONGOLDB CRUD Operations

Source: Internet
Author: User
> Db.user.insert ({username: ' Gugang '}) Writeresult ({"ninserted": 1}) > Db.user.insert ({username: ' Jones '})  Writeresult ({"ninserted": 1}) > Db.user.find () {"_id": ObjectId ("59454e7b961eb6f4b52b675f"), "username": "Gugang"  } {"_id": ObjectId ("59454e85961eb6f4b52b6760"), "username": "Jones"} > Db.user.find ({username: ' Gugang '}) {"_id": ObjectId ("59454e7b961eb6f4b52b675f"), "username": "Gugang"} > Db.user.find ({username: ' Jones '}) {"_id": ObjectId (" 59454e85961eb6f4b52b6760 ")," username ":" Jones "} > Db.user.find ({username: ' Gugang '}). Pretty () {" _id ": ObjectId ("
59454e7b961eb6f4b52b675f ")," username ":" Gugang "} > Db.user.find ({$or: [{Username:gugang}, {username:jones}]}) 2017-06-17t23:47:15.381+0800 E QUERY [Thread1] Referenceerror:gugang is not defined: @ (Shell): 1:21 > Db.user.find (
{$or: [{username: ' Gugang '}, {username: ' Jones '}]}
{"_id": ObjectId ("59454e7b961eb6f4b52b675f"), "username": "Gugang"} {"_id": ObjectId ("59454e85961eb6f4b52b6760")," username ":" Jones "} > Db.user.find ({$and: [{username: ' Gugang '}, {username: ' Jones '}]}) > Db.user.find ({$and:
[{username: ' Gugang '}, {id: ' 59454e7b961eb6f4b52b675f '}]} > Db.user.find ({$and: [{username: ' Gugang '}, {-id: ' 59454e7b961eb6f4b52b675f '}]}) 2017-06-18t00:06:14.006+0800 E QUERY [Thread1] Syntaxerror:invalid Property ID @ (Shell): 1:42 > Db.user.find ({$and: [{username: ' Gugang '}, {_id: ' 5945 4e7b961eb6f4b52b675f '}}) > Db.user.find ({$and: [{username: ' Gugang '}, {_id:objectid ("59454e7b961eb6f4b52b675f") }]} {"_id": ObjectId ("59454e7b961eb6f4b52b675f"), "username": "Gugang"} > Db.user.find ({_id: ' 59454e7b961eb6f4b52b675f '}) 2017-06-18t00:06:59.288+0800 E QUERY [Thread1] syntaxerror:missing; Before statement @ (Shell): 1:46 > Db.user.find ({' _id ': ' 59454e7b961eb6f4b52b675f '})) 2017-06-18t00:07:12.677+0800 E QUERY [Thread1] syntaxerror:missing; Before statement @ (Shell): 1:48 > Db.user.find ({$and: [{username: ' Gugang '}, {_id:objectid ("59454e7b961eb6f4b52b675f "}]}) {" _id ": ObjectId (" 59454e7b961eb6f4b52b675f ")," username ":" Gugang "} > Db.user.find ({' _id ': '})) 2017-06-1 8t00:07:32.374+0800 E QUERY [Thread1] syntaxerror:missing;
Before statement @ (Shell): 1:24 > Db.user.find ({' _id ': '} ') > Db.user.find ({' _id ': ' 59454e7b961eb6f4b52b675f '}) > Db.user.insert ({_id:1, username: ' Hello '}) Writeresult ({"ninserted": 1}) > Db.user.find ({' _id ': '}) > Db.use R.find ({}) {"_id": ObjectId ("59454e7b961eb6f4b52b675f"), "username": "Gugang"} {"_id": ObjectId ("59454e85961eb6f4b52 b6760 ")," username ":" Jones "} {" _id ": 1," username ":" Hello "} > Db.user.find ({_id:1}) {" _id ": 1," username ":"  Hello "} > Db.user.update ({username: ' Gugang '}, {$set: {county:" ""}}) Writeresult ({"nmatched": 1, "nupserted": 0, "Nmodified": 1}) > Db.user.find ({username: ' Gugang '}) {"_id": ObjectId ("59454e7b961eb6f4b52b675f"), "username": "G Ugang "," County ":" > Db.user.update "({username: ' Gugang '}, {county: ' Canada '}) WriTeresult ({"nmatched": 1, "nupserted": 0, "nmodified": 1}) > Db.user.find ({username: ' Gugang '}) > Db.user.find ({} {"_id": ObjectId ("59454e7b961eb6f4b52b675f"), "County": "Canada"} {"_id": ObjectId ("59454e85961eb6f4b52b6760"), "U Sername ":" Jones "} {" _id ": 1," username ":" Hello "} > Db.user.update ({County: ' Canada '}, {$set: {username: ' Gugang ') }}) Writeresult ({"nmatched": 1, "nupserted": 0, "nmodified": 1}) > Db.user.find ({username: ' Gugang '}) {"_id": OBJ Ectid ("59454e7b961eb6f4b52b675f"), "County": "Canada", "username": "Gugang"} > Db.user.update ({username: ' Gugang '} {$unset: {county:1}}) Writeresult ({"nmatched": 1, "nupserted": 0, "nmodified": 1}) > Db.user.find ({username: ' gu Gang '}} {"_id": ObjectId ("59454e7b961eb6f4b52b675f"), "username": "Gugang"} > Db.user.insert ({username: ' Gavin '}) W Riteresult ({"ninserted": 1}) > Db.user.find ({username: ' Gavin '}) {"_id": ObjectId ("59455576961eb6f4b52b6761"), "us Ername ":" Gavin "} > Db.uSer.update ({username: ' Gavin '}, {$set: {favorites:{cities:[' Beijing ', ' Tianjin '], movies: [' The Sting ', ' Casablanca ']} }}) Writeresult ({"nmatched": 1, "nupserted": 0, "nmodified": 1}) > Db.user.find ({username: ' Gavin '}). Pretty () {"_ ID ": ObjectId (" 59455576961eb6f4b52b6761 ")," username ":" Gavin "," Favorites ": {" Cities ": [" Beijing "," Tianj In "]," movies ": [" The Sting "," Casablanca "]}} > Db.user.find ({username: ' Gugang '}) {" _id ": ObjectId ("59454e7b961eb6f4b52b675f"), "username": "Gugang"} > Db.user.update ({username: ' Gugang '}, {$set: {favorites: {Citi es:[' Shanghai ', ' Chengdu '}}} writeresult ({"nmatched": 1, "nupserted": 0, "nmodified": 1}) > Db.user.find ({Userna Me: ' Gugang '}). Pertty () 2017-06-18t00:22:04.565+0800 E QUERY [thread1] TypeError:db.user.find (...). Pertty is not a function: @ (Shell): 1:1 > Db.user.find ({username: ' Gugang '}). Pretty () {"_id": ObjectId ("59454e7b961eb 6f4b52b675f ")," username ":" Gugang "," favoriTEs ': {"Cities": ["Shanghai", "Chengdu"]} > Db.user.update ({username: ' Gugang '}, {$addToSet: {' Favorit Es.cities ': ' Beijing '}}, False, True) Writeresult ({"nmatched": 1, "nupserted": 0, "nmodified": 1}) > Db.user.find ({ Username: ' Gugang '}). Pretty () {"_id": ObjectId ("59454e7b961eb6f4b52b675f"), "username": "Gugang", "Favorites": {" Cities ": [Shanghai", "Chengdu", "Beijing"]}} > Db.user.find () {"_id": ObjectId ("59454e7b961eb6f4b52 b675f ")," username ":" Gugang "," Favorites ": {" Cities ": [" Shanghai "," Chengdu "," Beijing "]}} {" _id ": ObjectId (" 59 454e85961eb6f4b52b6760 ")," username ":" Jones "} {" _id ": 1," username ":" Hello "} {" _id ": ObjectId (" 59455576961eb6f4b 52b6761 ")," username ":" Gavin "," Favorites ": {" Cities ": [" Beijing "," Tianjin "]," movies ": [" The Sting "," Casablanc A ']} > Db.user.remove ({_id:1}) Writeresult ({"nremoved": 1}) > Db.user.find () {"_id": ObjectId ("59454e7b961e b6f4b52b675f ")," UsernamE ":" Gugang "," Favorites ": {" Cities ": [" Shanghai "," Chengdu "," Beijing "]} {" _id ": ObjectId (" 59454e85961eb6f4b52 b6760 ")," username ":" Jones "} {" _id ": ObjectId (" 59455576961eb6f4b52b6761 ")," username ":" Gavin "," Favorites ": {" CIT IES ": [" Beijing "," Tianjin "]," movies ": [" The Sting "," Casablanca "]}} > Db.user.remove () 2017-06-18t00:27:57.16 9+0800 E QUERY [thread1] error:remove needs a QUERY:DBCOLLECTION.PROTOTYPE._PARSEREMOVE@SRC/MONGO/SHELL/COLLECTION.J S:409:1 dbcollection.prototype.remove@src/mongo/shell/collection.js:434:18 @ (Shell): 1:1 > Db.user.find () {"_id":  ObjectId ("59454e7b961eb6f4b52b675f"), "username": "Gugang", "Favorites": {"Cities": ["Shanghai", "Chengdu", "Beijing" ]} {"_id": ObjectId ("59454e85961eb6f4b52b6760"), "username": "Jones"} {"_id": ObjectId ("59455576961eb6f4b52b6761 ")," username ":" Gavin "," Favorites ": {" Cities ": [" Beijing "," Tianjin "]," movies ": [" The Sting "," Casablanca "]} } > Db.user.remove ({}) WrIteresult ({"Nremoved": 3}) > Db.user.find () >  
> Show Tables
user
> Db.user.drop ()
true
> Show Tables
> Db.help ()


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.