I have an application that uses mongo's oplog to follow insert, update and delete operations. I would like to get to full document through mongoose (populated), everytime one of the operations occur (findById with the id I get from the oplog), but I do not have the Schemas as there are defined in another application.
Do you think it is possible to get the full document without cloning the other application and registering each schemas for each model?
Thanks in advance!
Related
Is there a way to switch off the ability of mongo to sporadically create dbs and collections as soon as it sees one in a query. I run queries on the mongo console all the time and mistype a db or collection name, causing mongo to just create one. There should be a switch to have mongo only explicitly create dbs and collections. I can't find one on the docs.
To be clear, MongoDB does not auto create collections or databases on queries. For collections, they are auto created when you actually save data to them. You can test this yourself, run a query on a previously unknown collection in a database like this:
use unknowndb
db.unknowncollection.find()
show collections
No collection named "unknowncollection" shows up until you insert or save into it.
Databases are a bit more complex. A simple "use unknowndb" will not auto create the database. However, if after you do that you run something like "show collections" it will create the empty database.
I agree, an option to control this behavior would be great. Happy to vote for it if you open a Jira ticket at mongoDB.
No, implicit creation of collections and DBs is a feature of the console and may not be disabled. You might take a look at the security/authorization/role features of 2.6 and see if anything might help (although there's not something that exactly matches your request as far as I know).
I'd suggest looking through the MongoDB issues/bug/requests database system here to and optionally add the feature request if it doesn't already exist.
For people who are using Mongoose, a new database will get created automatically if your Mongoose Schema contains any form of index. This is because Mongo needs to create a database before it can insert said index.
I am a newbie to nosql world and I am stuck during the designing of my database.I am developing an app where there are two collections,
User
Leave
When a user applies for leave ,leave details will be added to leave collection and the leaveID(Mongo generated) will be added to the user collection depending on which user applied for leave.
Now my question is for adding the _id to the user collection ,Should i write one more query or is there any way to auto fill the user collection when a document is added to the leave Collection. ie should i write 2 queries to insert into the leave and user collection or with only one query the task could be completed.
I am using java driver for interacting with db.
In mongodb, with that collection structure, you'll have two use two requests, yes. One for inserting leave, another for inserting leave reference to a user document.
You could do with one request if your leaves were embedded in a user, but that might not make sense, according to your other requirements.
I am a beginner to MEAN stack,I have one doubt that if I want to use any database and schema in my app using mongoose .Is it important that the same database and schema should exist in mongo db before?
Mongodb is schema-less. In other words the schema lives in the application. So no separate schema definitely is required in Mongodb prior to using it. Both database and collection (schema) gets created on the fly while using it.
However if authentication is enabled in Mongodb, then the userid should have sufficient privilege to access the database and create collections within them.
I want to insert the current timestamp in a document, whenever a new document is inserted into the Database. I know that this can be doe using triggers in relational Databases. But I am not sure how to do that in NosQL databases like Cloudant.
It is probably worth you investigating update handlers:
Update handlers are custom functions that live on Cloudant’s server that will create or update a document. This can, for example, provide server-side modification timestamps, and document updates to individual fields without the latest revision.
Source https://docs.cloudant.com/design_documents.html#update-handlers
Is there a way to switch off the ability of mongo to sporadically create dbs and collections as soon as it sees one in a query. I run queries on the mongo console all the time and mistype a db or collection name, causing mongo to just create one. There should be a switch to have mongo only explicitly create dbs and collections. I can't find one on the docs.
To be clear, MongoDB does not auto create collections or databases on queries. For collections, they are auto created when you actually save data to them. You can test this yourself, run a query on a previously unknown collection in a database like this:
use unknowndb
db.unknowncollection.find()
show collections
No collection named "unknowncollection" shows up until you insert or save into it.
Databases are a bit more complex. A simple "use unknowndb" will not auto create the database. However, if after you do that you run something like "show collections" it will create the empty database.
I agree, an option to control this behavior would be great. Happy to vote for it if you open a Jira ticket at mongoDB.
No, implicit creation of collections and DBs is a feature of the console and may not be disabled. You might take a look at the security/authorization/role features of 2.6 and see if anything might help (although there's not something that exactly matches your request as far as I know).
I'd suggest looking through the MongoDB issues/bug/requests database system here to and optionally add the feature request if it doesn't already exist.
For people who are using Mongoose, a new database will get created automatically if your Mongoose Schema contains any form of index. This is because Mongo needs to create a database before it can insert said index.