This code is working fine on my local machine.
Bulk.find({"xyz":23}).upsert().update({$set : 5465});
Bulk.execute(function (err, data) {});
When I have moved this code to Azure, it wasnt working. I recognize that cosmosDB doesn't support upsert. Is that ryt ?
Reference :
https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb-feature-support#database-commands
Should i replace with find and insert or update as normal ? or is there any other solution available ? Please help.
Yes, based on the doc MongoDB query language support , upsert() command is not supported by cosmos db mongo api. As I known, no shortcuts here so far. You need to encapsulate methods to determine whether a document exists, and then decide to insert or update.
Or, just to declare that the Cosmos Document DB SDK supports Upsert method. Please refer to the case: How can I perform an UPSERT using Azure DocumentDB?.
Cosmos Document DB is a good choice if you could do data migrations.
Hope it helps you.
Related
I have Cosmos db as our database and my java application runs on Spring Boot. I'm using Spring Data's MongoRepository to query the database.
I have a requirement where I need to find results based on a field and it needs to be case insensitive.
What I tried ...
appending mongorepository method with "IgnoreCase"
adding regex in query ... #Query("{fieldName: {$regex: '^?0$', $options: 'i'}}")
The above solutions work with my mongodb(on my local) but doesn't work on cosmosdb .
I thought that the issue might be because of version of the software I'm using or some driver I'm using so I ran the same query on mongocompass (connecting to mongodb) and robo3t (connecting to cosmosdb), but the query doesn't with cosmos.
So my assumption is cosmos doesn't support the above queries
Now i'm not going to switch to mongodb since i'm not the one making the decision, i'm stuck with cosmos and I have to provide solution to the latter.
I've searched about collation, but haven't found any results or documentation on how to do it with cosmosdb and most likely this is not an option for me.
So is there any other way to query the database with no case sensitivity or is there anything wrong which I'm doing here?
UPDATE
The CosmoDB team confirmed that there is an issue on their said and they are already working on a fix.
More info in the comment section here: https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb-introduction
ORIGINAL QUESTION
we are planning to migrate to CosmoDB but we found an issue with the $sort command.
In our current MongoDB server running this query:
db.getCollection('Product').find({
"ProductTypeId" : ObjectId("5913546b1ba88338e4347641"),
"SubtypeIngredients" : "5949852c1ba88344d0facbf5"
})
.skip(0).sort({ "IngredientRanks.2.Rank" : 1 }).limit(1)
We get some results but when running the same query in CosmoDB we don't get any results.
if I remove the sort command from the query, I get results from CosmoDB
The data in the collection is the same in our local db and CosmoDB.
Any help would be appreciated.
Thanks!
Update:
Here is an screenshot of the actual query showing the issue.
There is no specific guarantee that CosmoDB supports all the operators and functions of MongoDB, particularly non-trivial use of the API (like chaining sort, skip , etc.). This extends to index optimization and selection as well.
This is what is mentioned in the cosmosdb website
I got 2 Azure Cosmos DB's which runs in MongoDb. The first one was created by someone else and second one was created by me.
If I query my database, my structure gets very weird with a $t and $v property.
My structure:
Structure of the other DB (like it should be):
My backend does work properly with both, but I want to add Azure Search and I can't do this with my structure. Why is this happening and how can I fix it?
(If someone can make this a comment instead of an answer, it would be appreciated)
I'm getting the same thing. It looks like Microsoft gave an answer here as to why it happens: http://answers.flyppdevportal.com/MVC/Post/Thread/e0ffdbcd-0b43-4cd5-9d21-1a95ce0279dd?category=azuredocumentdb
The incorrect format is a result of intermixing the Cosmos DB: MongoDB API with the Cosmos DB: DocumentDB API.
It's not very clear to me though why those two are intermixed since MongoDb maintains the MongoDB API NuGet.
This is happening because one of your Cosmos DB MOngoDB API accoutn is older than the other - older one uses JSON schema (used by SQL API as well), while newer uses more versatile (and MongoDB compliant) BSON schema. You just need to request the conversion of the account to a new schema by emailing askcosmosmongoapi#microsoft.com
I wanted to perform CRUD operations on azure-cosmosdb using the query on azure query-explorer.
How can I construct insert, update and delete query here.
I am unable to construct a single query.
I am constructing the query here:
The Query Explorer you are showing responds to Cosmos DB SQL syntax queries, not Mongo Query syntax (you can't do db.yourCollection.find for example).
When you create your Cosmos DB account, you can select if you want to use the Mongo API. If you are indeed working on a project that will use Mongo and you enable the Mongo API, you can run queries using Mongo syntax in the Data Explorer (in Preview) which is in the same vertical navigation menu.
The Data Explorer, for a Mongo-enabled Cosmos DB account, includes a Mongo Shell that let's you run the kind of commands you are looking for.
Parse query withinKilometers() is not working after I migrated the database to my own mongoDB server (No error, but response is empty).
The issue is being discussed in github
But they say it is issue of mongoDB version.
I tried using mongo 3.0.11 , 3.0.9 and 3.0.0
A workaround mentioned is by using cloud code, but the query fails in the cloud too.
Any one have some other workaround please help as the last date of parse data migration is around the corner.
We have to create index for our database column for mongoDB to support geoQuerry, by default it will not support it seems.
Solution:
db.prod.createIndex({ "location": "2d" })
Where prod is my collection name and location is name of column which stores geo location (GeoPoint)
Few more details about the issue is discussed here
Thanks