I started working with mongodb yesterday and can't seem to generate a database on the console. Every time I do the
use exampledb
switched to db exampledb
but for some reason I still generate only my locals..?
show dbs
local 0.078GB
I created a folder called /data/db in my root directory (following the tutorial) so I'm not sure what I am missing... help appreciated!
You are not missing anything. exampledb will be shown (using show dbs) only when you insert atleast one document in it. You can add collections manually if you want using db.createCollection().
Your database need to have atleast one document inside. First we need to add atleast one document into the selected database.
Example:
db.mycollection.insert({"name":"Max"})
where db is the general term not the name of the database and mycollection is the name of your collection, inside the insert give as key value pairs)
After that you can see your database.
Insert one Document and the "show dbs" command will display your database
Related
Currently I'm working on an application that is making queries on a given MarkLogic database, the default one as we can say, but to provide same values on the screen I have to check the role of the logged user before displaying. This can be done querying the Security database, the one provided by MarkLogic itself, but I don't know how to explicitly declare on the query that I want to query that particular database instead of the default one. Do you know some command that could help me? Thank you!
You can use eval to query against another database:
xdmp:eval("doc('/docs/mydoc.xml')", (),
<options xmlns="xdmp:eval">
<database>{xdmp:database("otherdb")}</database>
</options>)
See: https://docs.marklogic.com/xdmp:eval
Also, if you are querying the security database specifically, then instead of xdmp:database you can use xdmp:security-database.
I re-created my database on one of my dev environment and now when I run the migration via sequelize db:migrate, it tries to run the migrations from the first.
I don't want to re-sync/re-create the database since running migrations on the dev environment ensures that the migrations are correctly written.
Is there a way to force-mark some migrations as 'done'?
Sequelize-cli stores the migration data on a table called SequelizeMeta.
You can copy the migration filename from your existing DB and insert into the above mentioned table in new environment's DB.
All the migrations recorded would be considered as they have already ran.
Though this would stop selected migrations from running, it's not the best approach to be taken.
This metadata could also be stored in a json, though I am not very aware of the structure for it.
You can dig through the docs here
The actual way of doing is as follow,
There are two tables sequelizemeta and SequelizeMeta(Hidden)
And for skip or say migration already ran is enter value in both table like
INSERT INTO sequelizemeta (name) VALUES
('20181019072815-roles.js'),
('20181019093229-users.js')
INSERT INTO SequelizeMeta (name) VALUES
('20181019072815-roles.js'),
('20181019093229-users.js')
Note- SequelizeMeta is hidden table but we can query it.
SELECT * from seerportal.SequelizeMeta
I do not see any function in help about getting all existing databases in ArangoDB.
To get the list of all existing databases from the Arango console (I am referring to the ArangoShell here), you can use:
db._databases();
In case you are looking for other methods: the shell has auto-completion, so you can type db. and then press the tab key. This will show the list of available properties/functions for the given object if it exists (and is a variable).
Hi all I'm new to learning how to develop with Node.js using Mongoose and Express. I have been having some issues with Mongodb not correctly reflecting my schema changes.
For example, I have written a model that supposedly auto-increment _id by 1 starting from 0 when each new document is inserted. I'm testing a few ways to do this model and so I'm constantly inserting different data.
I drop the collection each time to try to reinsert the data. However, _id instead of starting at 0, it starts at the previous largest _id.
This is just one of the issues that I have encountered. Some other similar Schema changes that I did on the fly also were not reflected.
I tried the following:
Ending npm/nodemon
Ctrl+C from mongo
shutdownServer from mongo
Is there something else that I need to shut down completely then restart before mongoose reflects the newest form of the schema? Thanks!
To start fresh with a new schema, it's best (if possible) to drop the old database entirely (db.dropDatabase() from the MongoDB shell), otherwise you may run into various issues (that can also be solved separately, if dropping the database isn't an option):
left-over collections, like the one used by the autoincrement plugin that you're using (I think it'll use a collection called identitycounters);
left-over indexes, which happens when you define field names in your schema that should be indexed, and you subsequently rename or delete one of those fields;
Restarting the database server won't solve these, they do require some manual administration.
I have a CouchDB database in production. One of the documents has been edited (in Futon by an other developer).
And it's lost it's ID (don't ask me how he did it).
So now the document's id is an empty string, which makes it impossible to edit or delete via Futon.
Is there a way I could hack into CouchDB to delete that document anyway ?
I couldn't delete the document. But the database itself could be deleted.
And I couldn't reproduce the bug in locale. The other developer says he just removed the _id param and saved. I don't know what happened in CouchDB when he did it. But when I do so, it only recreates a new document (as we'd expect it to do).
So I've been using couch_docs to retrieve the datas locally.
As the id is empty, couch_docs doesn't imports it. So you don't even need to delete it manually.
Then I reimport all the records in an other database. I change the references to the database name in my config and everything works fine.
Destroying the database is not a problem even though there's an empty id.
Technically, a document ID is immutable so actually changing the _id field is not directly possible. Perhaps another document was created as a copy of the first?
A bug in CouchDB 1.1.0 allowed update functions to create empty string IDs.
A similar question asks about this and I gave a walkthrough of deleting empty ids there.
I haven't tried it but LoveSeat is supposed to be able to open and edit couchedb files...
This can be caused (and fixed!) by some error checking CouchDB was missing for _update handlers, as explained in How do you delete a couchdb document with an empty "" document id?