0
votes

I'm currently involved with a migration from a MongoDB instance to a Azure Cosmos DB instance. Because of this I am throwing out the mongo-java-driver dependency and replacing it with the latest azure-documentdb (version 2.4.0) dependency.

I have a trips collection in my foobar Azure Cosmos database with the following document structure:

{
    "_id" : ObjectId("5d0cdd6a6b1bb358985eb5d5"),
    "od" : 1561075200000,
    "rid" : "d001",
    "tnr" : 1007,
    "rsn" : 0,
    "p" : [
        {
            "s" : 1,
            "st" : "P",
            "sid" : "18003100",
        },
        {...}
    ]
}

The first thing I've tried for this migration project is to query my trips collection with a simple where statement which is codewise pretty much the same as in a example found here: https://github.com/Azure/azure-documentdb-java/

The problem is as follows. When I try to query the trips collection for documents where rid equals to d001 it gives back zero results with the following code. That shouldn't be the case since I have 9 matching documents in my trips collection.

DocumentClient client = new DocumentClient(
    HOST, 
    MASTER_KEY, 
    ConnectionPolicy.GetDefault(), 
    ConsistencyLevel.Session);

FeedOptions feedOptions = new FeedOptions();
FeedResponse<Document> query = client.queryDocuments(
    "dbs/foobar/colls/trips", 
    "SELECT * FROM trips t WHERE t.rid='d001'", 
    feedOptions);

List<Document> results = query.getQueryIterable().toList();
System.out.println(results.size());

Also changing the query to "SELECT t.rid FROM trips t" gives back zero results. Also changing the query to "SELECT * FROM trips t WHERE t['rid']='d001'" gives back zero results.

When I change the query to "SELECT * FROM trips t" everything seems just fine and it returns all documents in the collection.

What could be the problem here?

1

1 Answers

0
votes

Try with the following query,

FeedResponse<Document> query = client.queryDocuments(
    "dbs/foobar/colls/trips", 
    "SELECT * FROM trips t WHERE t.rid='d001'", 
    null).toBlocking().first();