Allan Visochek
Allan Visochek

Reputation: 55

Why can't I create a database in MongoDB

I can't seem to create a mongoDB database. I've read like 4 tutorials, and it seems like it should be pretty straight forward. Did I miss anything? Could I have a problem with my installation or something?

> use a
switched to db a
> a.abc.save({abc:"asdf"})
2015-04-17T01:39:45.723-0400 E QUERY    ReferenceError: a is not defined
at (shell):1:1
> a.abc.insert({abc:"asdf"})
2015-04-17T01:39:58.572-0400 E QUERY    ReferenceError: a is not defined
at (shell):1:1

Upvotes: 1

Views: 2875

Answers (1)

ZeMoon
ZeMoon

Reputation: 20274

Instead of

a.abc.save({abc:"asdf"})

Write

db.abc.save({abc:"asdf"})

When you use the command

use a

You make the system refer to the database a, which can be accessed using the keyword db. Please refer to the Getting Started With the Mongo Shell Guide.

Upvotes: 8

Related Questions