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?
Related
I have written a number of Presto queries that pull from mongoDB collections, but others in our project query mongo directly. These folks would like to use my queries to save them the time of having to rewrite them.
Is there a way to obtain/extract the mongoDB query language generated by Presto?
Didn't see anything in the MongoDB connector documentation that would indicate how or if this was possible.
I am aware of SQL-mongo converters out there, but Presto SQL extends normal SQL to enable things like unwrapping arrays etc. that we encounter with non-relational stores and these converts have trouble with these things in my experience.
You can set MongoDB driver log level DEBUG in log.properties:
org.mongodb=DEBUG
However, it will print many unrelated logs (e.g. healthcheck). Filed an issue https://github.com/prestosql/presto/issues/5600
I guess the easiest way is to look into Mongodb while the query is running and get it from there, for example via logging:
db.setProfilingLevel(2)
db.system.profile.find().pretty()
You may also use some GUIs like MongoVue or Robo 3T - I used MongoVue in the past to evaluate running queries.
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.
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.
I am using Apache Solr 6.3.0 and MongoDB 3.4 for advance text search features. I have successfully, synced mongodb with solr cores using mongo-connector 2.5 and solr doc manager.
I want to know the right way and practices to use solr with mongo and I have some issues that I need help on:
1). Now that my data is available both in mongo database and also indexed and stored in Solr cores, should I now query Solr all the time ? Or should I query solr for text search only and perform rest of the queries on mongo ?
2). Is there some way I could perform powerful search directly on mongo database using the indexing done by Solr ?
3). I have some collections that contain deeply nested json data and MongoDb supports them well. Solr indexes and stores such data in flattened form.But, I want to maintain the original nested json format in query response. Is this something I can achieve with Solr ?
Other suggestions about good practices of using solr with mongoDb will be extremely helpful.
If it makes sense to just query Solr, do that. If it makes sense to query Solr for certain data, do that. It depends on your use case, but if any query can be answered with the data in Solr, it's perfectly fine to use that for everything. That'll probably allow a more efficient use of your caches.
No, not that I know of.
Not really. Solr isn't well suited for nested JSON (even if you have parent/child documents, it's something you'll have to manually handle in every situation and will require special casing all over).
In those situations you can use Solr for querying, get the ids back and then retrieve the actual documents from mongo with their JSON structure intact. In that case you can leave most fields as non-stored in Solr.