MongoDB 3.0.1 mongodump error - mongodb

I need to create a dumpfile of a MongoDB db using 'mongodump'.
ubuntu-0864947#ubuntu-vm:~$ mongo
MongoDB shell version: 3.0.1
connecting to: test
Server has startup warnings:
2015-03-30T14:26:08.806+0200 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2015-03-30T14:26:08.807+0200 I CONTROL [initandlisten]
2015-03-30T14:26:08.807+0200 I CONTROL [initandlisten]
2015-03-30T14:26:08.807+0200 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-03-30T14:26:08.808+0200 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2015-03-30T14:26:08.808+0200 I CONTROL [initandlisten]
> mongodump
2015-04-30T15:56:00.719+0200 E QUERY ReferenceError: mongodump is not defined
at (shell):1:1
> mongodump RotterdamHaven
2015-04-30T15:56:15.970+0200 E QUERY SyntaxError: Unexpected identifier
> use RotterdamHaven
switched to db RotterdamHaven
> mongodump RotterdamHaven
2015-04-30T16:26:13.742+0200 E QUERY SyntaxError: Unexpected identifier
Can anyone please tell me what I am doing wrong here?
Thanks!

mongodump is an executable like mongo, you need to execute it in the OS shell, not in the MongoDB shell:
ubuntu-0864947#ubuntu-vm:~$ mongodump <arguments>

Just Go to bin Directory of Mongodb (mycase : c:\mongodb\bin)
Then,
Run : following Command
mongodump --db database_name
Then go to Dump Directory Created inside Bin Folder
There you'll find folder of your named database and inside that
.bson & .json file would be there just keep it safe .bson is your backup file
Cheers

Related

Kubuntu: Accessing mongodb?

Trying to get started with mongodb and linux at all, so got a preety stupid question, but anyways. How can i get into the mongodb(cmd) to send some of my queries.
Used
sudo mongodb serive start
already and cheked it's status, how can I access that space where i can type my queries?
The command is just mongo.
$ mongo
MongoDB shell version: 3.2.1
connecting to: test
Server has startup warnings:
2018-08-14T13:55:45.280-0400 I CONTROL [initandlisten]
2018-08-14T13:55:45.280-0400 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-08-14T13:55:45.280-0400 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-08-14T13:55:45.280-0400 I CONTROL [initandlisten]
> exit
bye

Can't run mongod ***aborting after fassert() failure on mac

I was working through the mongodb installation video on Mongodb university.
https://www.youtube.com/watch?v=_WJ8m5QHvwc
I am a mac user and encountered this problem when I initially tried to run mongod command for the first time. I am a new mongodb user and I would appreciate help with this. Thank you.
Edit: The first step I took was finding the download page on google. I selected the first organic link. I did not download the cloud service. I downloaded it and installed it onto my machine. I downloaded the most recent production version. I used the mac download.
Next, after the downloading, I went into the downloads directory in my terminal to untar the file by
tar xvf mongodb-osx-ssl-x86_64-3.4.3.tgz
That expanded the tarball. I entered the directory using
cd mongodb-osx-ssl-x86_64-3.4.3
and looked around. I saw a licence, a readme, and a bin directory.
I went into the bin directory.
cd bin
Next, I looked inside the bin directory
ls -l
I saw a bunch of mongo programs. In here I found mongo (shell) and mongod (server). Now I understand that the server will put its data in /data/db by default.
Next I proceeded to make that directory. I went root in order to do this by running
sudo bash
I then ran
mkdir -p /data/db
chmod 777 /data
chmod 777 /data/db
Next, I exited the root shell. I then looked inside the bin directory.
Roberts-MacBook-Air:Downloads robertchecco$ cd mongodb-osx-x86_64-3.4.3
Roberts-MacBook-Air:mongodb-osx-x86_64-3.4.3 robertchecco$ ls
GNU-AGPL-3.0 README bin
MPL-2 THIRD-PARTY-NOTICES
Roberts-MacBook-Air:mongodb-osx-x86_64-3.4.3
robertchecco$ cd bin
Roberts-MacBook-Air:bin robertchecco$ ls
bsondump mongodump mongoimport mongoreplay mongostat
mongo mongoexport mongooplog mongorestore mongotop
mongod mongofiles mongoperf mongos
Roberts-MacBook-Air:bin robertchecco$ ./mongod
2017-03-28T23:07:48.262-0400 I CONTROL [initandlisten] MongoDB starting : pid=77503 port=27017 dbpath=/data/db 64-bit host=Roberts-MacBook-Air.local
2017-03-28T23:07:48.263-0400 I CONTROL [initandlisten] db version v3.4.3
2017-03-28T23:07:48.263-0400 I CONTROL [initandlisten] git version: f07437fb5a6cca07c10bafa78365456eb1d6d5e1
2017-03-28T23:07:48.264-0400 I CONTROL [initandlisten] OpenSSL version: OpenSSL 0.9.8zh 14 Jan 2016
2017-03-28T23:07:48.264-0400 I CONTROL [initandlisten] allocator: system
2017-03-28T23:07:48.264-0400 I CONTROL [initandlisten] modules: none
2017-03-28T23:07:48.264-0400 I CONTROL [initandlisten] build environment:
2017-03-28T23:07:48.264-0400 I CONTROL [initandlisten] distarch: x86_64
2017-03-28T23:07:48.264-0400 I CONTROL [initandlisten] target_arch: x86_64
2017-03-28T23:07:48.264-0400 I CONTROL [initandlisten] options: {}
2017-03-28T23:07:48.265-0400 W - [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
2017-03-28T23:07:48.267-0400 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock Permission denied
2017-03-28T23:07:48.267-0400 I - [initandlisten] Fatal Assertion 28578 at src/mongo/util/net/listen.cpp 194
2017-03-28T23:07:48.267-0400 I - [initandlisten]
***aborting after fassert() failure

absolute path with database and collection name - not "use dbname" before command

How to specify in MongoDB 3.2.8 an absolute path?
I do this
use mydb
db.mycollection.findOne()
Howto write that without use mydb? The absolute path to db and collection. I use mongo shell.
Edit after first answer:
I have many databases and when specify a database a login time, to switch database I would again have to use use otherdb. I really wish some kind of absolute path, this is also possible in MariaDB/MySQL (select * from mydb.mytable).
when you connect to mongod when open console, you can specify db to conncet to:
$ mongo mydb
MongoDB shell version: 3.2.7
connecting to: mydb
Server has startup warnings:
2016-08-27T00:21:59.200+0300 I CONTROL [initandlisten]
2016-08-27T00:21:59.200+0300 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-08-27T00:21:59.200+0300 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-08-27T00:21:59.200+0300 I CONTROL [initandlisten]
2016-08-27T00:21:59.200+0300 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-08-27T00:21:59.200+0300 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-08-27T00:21:59.200+0300 I CONTROL [initandlisten]
> db
mydb

Mongodb how to connect and import data

I installed mongodb in Mac by homebrew. Then I tried to start it by mongodb. Failed. Then I start it by mongod --dbpath /data/db. Then it is waiting forever. How to start mongodb?
2015-08-22T16:08:52.619+0100 I CONTROL [initandlisten] build info: Darwin mimac 14.4.0 Darwin Kernel Version 14.4.0: Thu May 28 11:35:04 PDT 2015; root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
2015-08-22T16:08:52.619+0100 I CONTROL [initandlisten] allocator: system
2015-08-22T16:08:52.619+0100 I CONTROL [initandlisten] options: { storage: { dbPath: "/data/db/" } }
2015-08-22T16:08:52.628+0100 I NETWORK [initandlisten] waiting for connections on port 27017
To start mongodb automatically you can use command:
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist;
mongod is the daemon (i.e the mongoDB server itself). you should run it, as you did.
after there is a running server, you can:
run the mongo shell, with the mongo command. this would give you an interface to the databases you have, such as querying and inserting data.
to import an external file into mongo database, you should use the mongoimport command line tool, which is provided with mongodb.
mongoimport -d database_name -c collection_name < filename.json
mongoimport can import json, csv and tsv files.

"db.createUser is not a function" and "password can't be empty"

I am trying to setup the authentication on MongoDB. I've uncommented auth=true in configuration file and restarted the server. The first connection via mongo was rejected. The second one (immediately after the first one) went through and I got this in the logs:
Sat Apr 12 14:56:46 [initandlisten] connection accepted from 127.0.0.1:44001 #1
Sat Apr 12 14:56:46 [conn1] note: no users configured in admin.system.users, allowing localhost access
While in console, I am able to execute commands, however if I try to follow any of the numberous tutorials (including the official ones), I get either db.createUser is not a function when executing db.createUser() or password can't be empty when executing db.addUser():
The object which I am passing is:
{
user: "username",
pwd: "passphrase",
roles: [
{
role: "userAdminAnyDatabase",
db: "admin"
}
]
}
What version of mongodb are you running? db.createUser was introduced in version 2.6
Deprecated since version 2.6: Use db.createUser() and db.updateUser() instead of db.addUser() to add users
to MongoDB.
In 2.6, MongoDB introduced a new model for user credentials and privileges, as described in Security Introduction. To use db.addUser() on MongoDB 2.4, see db.addUser() in the version 2.4 of the MongoDB Manual.
http://docs.mongodb.org/manual/reference/method/db.addUser/
Regarding my experience, this issue also happens when you have an old version of Mongo Shell.
So, be sure to have the Mongo Shell according to the version of your MongoDB Server.
$ mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Below:
$ mongo
MongoDB shell version v3.4.10
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Server has startup warnings:
2018-01-16T11:43:00.195-0600 I STORAGE [initandlisten]
2018-01-16T11:43:00.195-0600 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2018-01-16T11:43:00.195-0600 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten]
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten]
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten]
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-01-16T11:43:00.687-0600 I CONTROL [initandlisten]
>
> use admin
switched to db admin
>
> db.createUser( {user:"mongoloide", pwd:"mongoloide*2017", roles:["root"]} )
Successfully added user: { "user" : "mongoloide", "roles" : [ "root" ] }