Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The connection of MongoDB under Mac

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

There's not so much chicken soup. Start connecting.

See a quick start MongoDB tutorial on the Internet, post an address and make a note.

One: connect

In the previous section, we installed ManogoDB. If you have successfully installed it, then open a new terminal and enter the following instructions to connect.

Mongo

As shown below, good, you have succeeded ~ you can operate on the command line.

MongoDB shell version: 3.2.8

Connecting to: test

Welcome to the MongoDB shell.

For interactive help, type "help".

For more comprehensive documentation, see

Http://docs.mongodb.org/

Questions? Try the support group

Http://groups.google.com/group/mongodb-user

Server has startup warnings:

2016-08-02T19:16:07.239+0800 I CONTROL [initandlisten]

2016-08-02T19:16:07.239+0800 I CONTROL [initandlisten] * * WARNING: soft rlimits too low. Number of files is 256, should be at least 1000

>

>

>

If you do not install mongodb successfully, you may make the following error.

MongoDB shell version: 3.2.8

Connecting to: test

2016-08-02T18:14:33.677+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1 thread1 27017, reason: errno:61 Connection refused

2016-08-02T18:14:33.678+0800 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1 purl 27017, connection attempt failed:

Connect@src/mongo/shell/mongo.js:229:14

@ (connect): 1:6

Exception: connect failed

So, if it fails, refer to the previous section ~ under installation ~

Two: add, delete, modify and check

1: database

(1) query existing databases

Show dbs

For the first installation, a database like the following appears

Local 0.000GB

(2) install the database

Use database name (e.g. test)

If there is a database with the same name, switch to the existing one, and if not, a new one will be created.

Switched to db test

2: collection

(1) create a collection

Db.createCollection ("Collection name: such as (mycollection)")

Results:

{"ok": 1}

(2) View the collection

Show collections

Results:

Mycollection (the name of the collection created)

3: add: insert (take collection mycollection as an example)

Db.mycollection.insert ({name: "liujinhuan"})

Results:

WriteResult ({"nInserted": 1})

4: check: find (take collection mycollection as an example)

Db.mycollection.find () .pretty ()

Results:

{"_ id": ObjectId ("57a0871725ae4f21a42b44e3"), "name": "liujinhuan"}

5: change: update (take collection mycollection as an example). Change name to TTTTTT if it is liujinhuan

Db.mycollection.update ({'name':'liujinhuan'}, {$set: {' name':'TTTTTT'}})

Results:

WriteResult ({"nMatched": 1, "nUpserted": 0, "nModified": 1})

6: delete: remove (take collection mycollection as an example)

Db.mycollection.remove ({"name": "liujinhuan"})

Results:

WriteResult ({"nRemoved": 1})

Three: visual operation tools

The above operations are all performed by inputting instructions in the terminal ~ recommend a visual operation tool Robomongo~

It's too late ~ tomorrow's physical examination ~ go to bed early ~

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report