Simple CRUD operations mongodb

Note: mongodb (non-relational | cache type)

The simple operation portion mongodb

  Library:

    View Gallery:

        show dbs

        db: View library which is currently under

    Create a library:

        use the library name ------- If the library already exists, the switch to the library, on the contrary, the process of creating action

  Table | collection:

    Create a collection:

        db.createCollection ( 'collection name', [layout condition]);

        Note: the layout condition = "{size: file size, capped: true, max: Article Number | document number}. --- capped quantified: DB table (set) .isCapped () ---- true / false whether quantitative

    Charles: show collections / db.getCollectionNames (); ---- Returns an array

    . Delete: db table | collection .drop ()

  Documents | data:  

    By:.. Db set .save ({}) db set .insert ({}) db.insertOne ({}) ------ add a

      db. collection .save ([{}, {}]) / db. collection .insert ([{}, {}]) a plurality of

      Note: insert will not replace the system ID save

    Delete: db set .deleteOne ({ "": ""});. Db set .remove. ({ "": ""}, True); an

      . Db set .remove ({condition}); a plurality of

      db. collection .remvoe ({}) Empty Table

  Change: db set .Update (query {}, {} Alternatively conditions, BL inserted, all change bl);.

    After replacing: {$ set: {data}, $ inc: {age: 1}}

  Charley: db collection .find ( "": "");

    Article Number: db set .find () count ();..

  . Deduplication: db set .distinct (key);

    condition

      {age:22};        -----age == 22

         {age:{$gt:22}};         ---age > 22  

      {age:{$lt:22}};         ---age < 22

      {age:{$lte:122,$gte:22}};    ----age <= 122 && age >=22

      {$or:[{age:22},{age:122}]}   ----22 or 122

      {key:value,key2,value2}      ---- value && value2

    db set .find ({condition column region to be displayed, {}}) ------ whether designated areas: an area name: a display region domain: 0

    Limited to:  

      db. collection .find (). limit (number) is defined

      db. collection .find (). skip (number) skip

    row:

      L: db set .find () sort ({key: 1, key2: -1})..;

      Down: db set .find () sort ({key: -1});..

      . Db set .find ({condition}, {display area designated}) skip (10) .limit (10) .sort ({key: 1}).

      db.insertOne ({description data})

There are a lot of wrong, please point out

 

Guess you like

Origin www.cnblogs.com/nongfusanquan/p/11571901.html