1

Exception:

System.FormatException: Invalid JSON number '2L'.
   at MongoDB.Bson.IO.JsonScanner.GetNumberToken(JsonBuffer buffer, Int32 firstChar)
   at MongoDB.Bson.IO.JsonScanner.GetNextToken(JsonBuffer buffer)
   at MongoDB.Bson.IO.JsonReader.PopToken()
   at MongoDB.Bson.IO.JsonReader.ReadBsonType()
   at MongoDB.Bson.Serialization.Serializers.BsonDocumentSerializer.DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)

Shard key definition, which is a composite key created by the constructor;

public string ShardKey { get; set; }

Query code:

    public virtual async Task<ICollection<City>>(City city)
    {
        string shardKey = city.CityNumber + city.ShortName;
        return await MongoDb.CitiesCollection.Aggregate().Match({
        "{ 'Time': { $elemMatch: { $eq: 0 } }," + " ShardKey: " + shardKey + " }")
            .ToListAsync();
    }

Why does this fail?

4

1 回答 1

0

Wrap the value containing the number like:

" ShardKey: '" + shardKey + "' }"

with single quotation marks.

I haven't been able to find this documented anywhere though. But it makes the my integration test run so :)

于 2018-07-25T10:40:54.557 回答