This question already has answers here:
MongoDB collection hyphenated name
(2 answers)
Closed 4 months ago.
I am trying to rename/drop, a Mongo collection where I have inadvertently put a . (dot) at the end of the DB collection name so the collection name looks like this:
collectionName.
I'm not able to find a way to use the collection name including the dot to either drop or rename the collection without getting an error back.
Any suggestions whether this is possible.
Check the docs
> use mytestdb
> db.orders.renameCollection( "orders2015" )
Related
This question already has answers here:
Mongodb text search multiple fields
(2 answers)
mognoose searching with regular expression in multiple columns
(2 answers)
Closed 5 years ago.
Hello I am new at mongodb , I have made server side pagination , working perfect, I have one search textbox in which I type anithing like email , name , number etc it should give me result but I am facting issue in serverside searching data from all field of single table , can anyone give me idea how can I do that
This question already has answers here:
Test empty string in mongodb and pymongo
(4 answers)
Closed 5 years ago.
I am working on a application built in PHP using MongoDB as a database.
Data is organized across BSON documents into a collection in MongoDB.
I need to retrieve only those documents where field containing string value is non empty value. I searched for functions equivalent to empty and strlen functions belonging to PHP language but did not get any relevant search results.
try this,
$cursor = $collection->find(array("someField" => array('$ne' => null)));
This question already has answers here:
Why this update query only update one record once
(3 answers)
Closed 7 years ago.
I'm a beginner in MongoDb.I wanted to know what is the query to remove a field in Mongo DB Collection.I have tried with
db.Component.update({},{$unset: {vendor:""}}).
Its was updating only first document.So How to remove field Completely from Collection?
Try this-db.Component.update({},{$unset: {vendor:""}},false,true)
Here false
This question already has answers here:
MongoDb query condition on comparing 2 fields
(4 answers)
Closed 8 years ago.
Is it possible to find all documents in a collection where documents with field (_id) values exist in another field (ex. parentID). Taking in consideration that both fields exist in the documents of the same collection? Thanks
Categories.find({'_id': 'parentID'})
{
_id: 11,
parentID: 1
}
I am using MongoDB 2.6.7
Yes, this is easy to do with the $where operator.
db.Categories.find({'$where':"this._id === this.parent"})
This gives you more flexibility than your regular find syntax but be warned that MongoDB needs to evaluate the Javascript so this is slower than a regular query.
This question already has answers here:
MongoDB - how to query for a nested item inside a collection?
(3 answers)
Closed 9 years ago.
Consider my query to be: {cheese:"Cheddar"} and I have the following collections:
{vegetable:"Lettuce", cheese:"Cheddar"}, {cheese:"Blue"}, {milk:"Chocolate}, {cheese:"Cheddar"}
How do I make a find that returns me all collections that include cheese:Cheddar?
The result would be {vegetable:"Lettuce", cheese:"Cheddar"}, {cheese:"Cheddar"} but right now it fives me just {cheese:"Cheddar"}. From what I investigated I only found tokens to work with arrays.
I do NOT know the name of the property is cheese, nor do I know if there are any other ingredients.
I am looking for a way to get documents from a collection, where the query is included in a field, by the names of the properties in the query and the respective values.
Using db.collection.findOne({cheese:"Cheddar"}) you will get as a result only one document, maybe {cheese:"Cheddar"} or maybe {vegetable:"Lettuce", cheese:"Cheddar"}, the first one that MongoDB finds depending on the _id field. If what you want is getting both, you should use db.collection.find({cheese:"Cheddar"}).