Get count of documents from a cursor [duplicate]
This question already has an answer here:
Get a count of total documents with MongoDB when using limit
9 answers
Limiting results in MongoDB but still getting the full count?
5 answers
Mongo C# driver 2.0 - Find count without fetching documents
1 answer
I am using this block of code to find documents in a collection.
Can I get the count of documents from a cursor ?
Or is there a way I can get only the count of documents by giving the findoptions ?
using (var cursor = await collection.FindAsync(filterExpression, new FindOptions<BsonDocument, BsonDocument>
{
Projection = projectionDef,
Skip = findOptions.Skip,
Limit = findOptions.Limit,
Sort = sortExpression
}, cancellationToken).ConfigureAwait(false))
{
while (await cursor.MoveNextAsync().ConfigureAwait(false))
{
foreach (var document in cursor.Current)
{
var docObject = BsonSerializer.Deserialize<object>(document);
var x = JObject.FromObject(docObject);
result.Add(x);
}
}
}
I am using mongo db driver 2.4.4
c# mongodb
marked as duplicate by Neil Lunn
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 8:56
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Get a count of total documents with MongoDB when using limit
9 answers
Limiting results in MongoDB but still getting the full count?
5 answers
Mongo C# driver 2.0 - Find count without fetching documents
1 answer
I am using this block of code to find documents in a collection.
Can I get the count of documents from a cursor ?
Or is there a way I can get only the count of documents by giving the findoptions ?
using (var cursor = await collection.FindAsync(filterExpression, new FindOptions<BsonDocument, BsonDocument>
{
Projection = projectionDef,
Skip = findOptions.Skip,
Limit = findOptions.Limit,
Sort = sortExpression
}, cancellationToken).ConfigureAwait(false))
{
while (await cursor.MoveNextAsync().ConfigureAwait(false))
{
foreach (var document in cursor.Current)
{
var docObject = BsonSerializer.Deserialize<object>(document);
var x = JObject.FromObject(docObject);
result.Add(x);
}
}
}
I am using mongo db driver 2.4.4
c# mongodb
marked as duplicate by Neil Lunn
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 8:56
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
If you have a "new question" then ask a new question just like the box there is telling you to do. Please don't change questions from the basic thing they originally asked, especially when marked to an existing duplicate or answered directly. New Question, new post. That's how it works here. Please follow the guidelines everyone else does.
– Neil Lunn
Nov 19 '18 at 15:00
add a comment |
This question already has an answer here:
Get a count of total documents with MongoDB when using limit
9 answers
Limiting results in MongoDB but still getting the full count?
5 answers
Mongo C# driver 2.0 - Find count without fetching documents
1 answer
I am using this block of code to find documents in a collection.
Can I get the count of documents from a cursor ?
Or is there a way I can get only the count of documents by giving the findoptions ?
using (var cursor = await collection.FindAsync(filterExpression, new FindOptions<BsonDocument, BsonDocument>
{
Projection = projectionDef,
Skip = findOptions.Skip,
Limit = findOptions.Limit,
Sort = sortExpression
}, cancellationToken).ConfigureAwait(false))
{
while (await cursor.MoveNextAsync().ConfigureAwait(false))
{
foreach (var document in cursor.Current)
{
var docObject = BsonSerializer.Deserialize<object>(document);
var x = JObject.FromObject(docObject);
result.Add(x);
}
}
}
I am using mongo db driver 2.4.4
c# mongodb
This question already has an answer here:
Get a count of total documents with MongoDB when using limit
9 answers
Limiting results in MongoDB but still getting the full count?
5 answers
Mongo C# driver 2.0 - Find count without fetching documents
1 answer
I am using this block of code to find documents in a collection.
Can I get the count of documents from a cursor ?
Or is there a way I can get only the count of documents by giving the findoptions ?
using (var cursor = await collection.FindAsync(filterExpression, new FindOptions<BsonDocument, BsonDocument>
{
Projection = projectionDef,
Skip = findOptions.Skip,
Limit = findOptions.Limit,
Sort = sortExpression
}, cancellationToken).ConfigureAwait(false))
{
while (await cursor.MoveNextAsync().ConfigureAwait(false))
{
foreach (var document in cursor.Current)
{
var docObject = BsonSerializer.Deserialize<object>(document);
var x = JObject.FromObject(docObject);
result.Add(x);
}
}
}
I am using mongo db driver 2.4.4
This question already has an answer here:
Get a count of total documents with MongoDB when using limit
9 answers
Limiting results in MongoDB but still getting the full count?
5 answers
Mongo C# driver 2.0 - Find count without fetching documents
1 answer
c# mongodb
c# mongodb
edited Nov 19 '18 at 9:31
Code-47
asked Nov 19 '18 at 8:50
Code-47Code-47
224
224
marked as duplicate by Neil Lunn
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 8:56
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Neil Lunn
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 8:56
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
If you have a "new question" then ask a new question just like the box there is telling you to do. Please don't change questions from the basic thing they originally asked, especially when marked to an existing duplicate or answered directly. New Question, new post. That's how it works here. Please follow the guidelines everyone else does.
– Neil Lunn
Nov 19 '18 at 15:00
add a comment |
If you have a "new question" then ask a new question just like the box there is telling you to do. Please don't change questions from the basic thing they originally asked, especially when marked to an existing duplicate or answered directly. New Question, new post. That's how it works here. Please follow the guidelines everyone else does.
– Neil Lunn
Nov 19 '18 at 15:00
If you have a "new question" then ask a new question just like the box there is telling you to do. Please don't change questions from the basic thing they originally asked, especially when marked to an existing duplicate or answered directly. New Question, new post. That's how it works here. Please follow the guidelines everyone else does.
– Neil Lunn
Nov 19 '18 at 15:00
If you have a "new question" then ask a new question just like the box there is telling you to do. Please don't change questions from the basic thing they originally asked, especially when marked to an existing duplicate or answered directly. New Question, new post. That's how it works here. Please follow the guidelines everyone else does.
– Neil Lunn
Nov 19 '18 at 15:00
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you have a "new question" then ask a new question just like the box there is telling you to do. Please don't change questions from the basic thing they originally asked, especially when marked to an existing duplicate or answered directly. New Question, new post. That's how it works here. Please follow the guidelines everyone else does.
– Neil Lunn
Nov 19 '18 at 15:00