I have set up `mongo' DB on my machine using the following docker-compose file.
version: "3.1"
services:
mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
volumes:
- ${PWD}/data:/usr/src/data
Now, I want to insert sample data into a collection named books using the below command
mongo books < booksJson.js
But when I execute this command I am getting the following error
MongoDB shell version v4.4.1
connecting to: mongodb://127.0.0.1:27017/books?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("57936227-aa22-4d5f-841b-59788847bc3c") }
MongoDB server version: 4.4.1
WriteCommandError({
"ok" : 0,
"errmsg" : "command insert requires authentication",
"code" : 13,
"codeName" : "Unauthorized"
})
bye
Below are the contents of my booksJson.js file.
db.books.insert([
{
title: 'xyz',
test: 1
}
])
Any pointers towards how to use mongo.exe to import JSON data using a JavaScript file and redirection operator?
mongo --db library -u username -p password books < booksJson.jsError parsing command line: unrecognised option '--db'