[CSHARP-1812] MongoCollection.Count() is not correct Created: 26/Oct/16  Updated: 22/Dec/16  Resolved: 22/Dec/16

Status: Closed
Project: C# Driver
Component/s: Operations
Affects Version/s: 2.4.0-beta1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Hu Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

var cursor = mongoCol.FindAllAs<BsonDocument>()
.SetSkip(currentDataViewInfo.SkipCnt)
.SetLimit(currentDataViewInfo.LimitCnt);

the SkipCnt and LimitCnt is 0.

var dataList = cursor.ToList();
// the Length of datalist is 2;

var CurrentCollectionTotalCnt = (int)mongoCol.Count(); //CurrentCollectionTotalCnt is 1

//Test Record is below

/* 1 */
{
"_id" :

{ "$oid" : "58105ee802f2b624c09971bb" }

,
"loc" :

{ "type" : "Point", "coordinates" : [-73.97, 40.77] }

,
"name" : "Central Park",
"category" : "Parks"
}
/* 2 */
{
"_id" :

{ "$oid" : "58105ef902f2b624c09971bc" }

,
"loc" :

{ "type" : "Point", "coordinates" : [-73.88, 40.78] }

,
"name" : "La Guardia Airport",
"category" : "Airport"
}



 Comments   
Comment by Hu [ 27/Oct/16 ]

https://jira.mongodb.org/browse/SERVER-26802
Please close this issue.

Comment by Hu [ 27/Oct/16 ]

HardCopy of this issue:
https://jira.mongodb.org/secure/attachment/142592/TestCSharp1812.PNG

Comment by Hu [ 27/Oct/16 ]

Really,If I use your code,the count is correct.
Then I redo my operation,create a collection,insert 2 records,the count is correct now.
So I think the driver is OK,but maybe some problem in server-side.
If you are interesting with the problem,I send my test database and run.bat to you.
http://files.cnblogs.com/files/TextEditor/TestCSharp1812.zip

MongoBooster/places has 2 record,but result is 1.
MongoBooster/place2 has 2 record,but result is 2.

Comment by Robert Stam [ 26/Oct/16 ]

I am unable to reproduce this.

Using the following standalone test program both documentCount and collectionCount are equal to 2.

using System.Linq;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
 
namespace TestCSharp1812
{
    public static class Program
    {
        public static void Main(string[] args)
        {
            var client = new MongoClient("mongodb://localhost");
            var server = client.GetServer();
            var database = server.GetDatabase("test");
            var collection = database.GetCollection("test");
 
            CreateCollection(database, collection);
 
            var cursor = collection.FindAllAs<BsonDocument>()
                .SetSkip(0)
                .SetLimit(0);
            var documents = cursor.ToList();
            var documentCount = documents.Count;
 
            var collectionCount = collection.Count();
        }
 
        private static void CreateCollection(MongoDatabase database, MongoCollection<BsonDocument> collection)
        {
            database.DropCollection("test");
            collection.Insert(BsonDocument.Parse("{ \"_id\" : { \"$oid\" : \"58105ee802f2b624c09971bb\" }, \"loc\" : { \"type\" : \"Point\", \"coordinates\" : [-73.97, 40.77] }, \"name\" : \"Central Park\", \"category\" : \"Parks\" }"));
            collection.Insert(BsonDocument.Parse("{ \"_id\" : { \"$oid\" : \"58105ef902f2b624c09971bc\" }, \"loc\" : { \"type\" : \"Point\", \"coordinates\" : [-73.88, 40.78] }, \"name\" : \"La Guardia Airport\", \"category\" : \"Airport\" }"));
 
            var keys = IndexKeys.GeoSpatialSpherical("loc");
            var options = IndexOptions.Null;
            collection.CreateIndex(keys, options);
        }
    }
}

Comment by Hu [ 26/Oct/16 ]

DB:MongoDB 3.4 RC1
Index:2dsphere against loc field

I found that MongoBooster(a mongo admin tool) has the same bug.
Maybe it is a server-side bug...

Generated at Wed Feb 07 21:40:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.