Syntax: Db.collection.save (collections); or Db.collection.insert (collections);
There are two ways of inserting.
1. Borrowing objects to insert
>item={id:1,name: "Hello"}>db.lottu.insert (item)
2. Insert data in a loop; Insert 5 records at once this is pretty good.
>for (i=1;i<=5;i++) Db.lottu.insert ({id:i,name: "KK"})
3. View data
Syntax: Db.collection.update (c1, $set, Multi,upsert)
1. Update a record
Update id=2 's record name is Lottu
>update Lottu Set name = ' Lottu ' where id=2
Then I was naughty; I wanted to change id=1 's record to Lottu.
The strange thing is: Why only one record is updated.
2. Update multiple records
Here we look for solutions. In MongoDB update multiple strips need to add multi (many) this parameter is True
>db.lottu.update ({id:1},{$set: {name: "li0924"},{multi:true}})
The update was successful. I don't think I lied to you.
Summary: Do not add multi parameters; By default, only one is updated. Add {multi:true} to update more than one
3. Update records that do not exist.
Update records that do not exist in Oracle, and the records do not change. Where's MongoDB?
Update records for ID=10
This, of course, does not change in MongoDB. No change is I didn't add upsert parameter; Now I add the next
This seems to have no record; This is somewhat similar to the merge into statement. But the concept is not the same.
Summary: {upsert:true}, this record is not added.
Syntax: Db.collecion.remove (C1)
Here, remove is equivalent to the DELETE statement in SQL
For example, delete a record with an ID of 10;id 5
>delete from Lottu where id = 10;
>delete from Lottu where id = 5;
This is nothing to explain.
>delete from Lottu? Delete all records?
Is it Db.lottu.remove ()?
The result is: Db.lottu.remove ({})
We know that delete can delete records, but we do not delete the table. This, of course, is the same in MongoDB.
The object is deleted only on the drop table.
And what about the drop in MongoDB?
4. MongoDB Insert, modify, delete operation