mongo Db unsupported filter type when using Any() or Contains() - Are there any workarounds / fixes?












3














i have seen other threads for this kind of question but none of the highlighted answers work for me.



The piece of code that throws the error is this



List<Distribution> distributionPublishQueueList = (mongoDb.GetCollection<Distribution>().Find(Builders<Distribution>.Filter.And(
Builders<Distribution>.Filter.Where(x => x.Status == EntityStatus.Ok),
Builders<Distribution>.Filter.Where(x => x.IsActive),
Builders<Distribution>.Filter.Where(x => distinctDistributionIdInPublishQueueList.Contains(x.Id))))).ToList();


The original code was this:



List<Distribution> distributionPublishQueueList = 
(await mongoDb.GetCollection<Distribution>()
.FindAsync(x => x.Status == EntityStatus.Ok
&& x.IsActive
&& distinctDistributionIdInPublishQueueList.Contains(x.Id)))
.ToList();


but i tried to make it more mongo friendly. Both pieces of code above are the same. The list distinctDistributionIdInPublishQueueList is a list of distribution Id's which are strings. So i am trying to find all distributions which Id is inside of that list + the other 2 filters. When i use the contains inside of the filter definition it throws an Unsupported filter exception. But the following code works because i bring the list into local memory and use LINQ against it:



List<Distribution> distributionPublishQueueList = (await mongoDb.GetCollection<Distribution>().FindAsync(x => x.Status == EntityStatus.Ok && x.IsActive)).ToList();
distributionPublishQueueList = distributionPublishQueueList.Where(x => distinctDistributionIdInPublishQueueList.Contains(x.Id)).ToList();


I need to be able to not do this in local memory due to the amount of Distributions that are present in the database. Is there a workaround to using Contains and Any. I have also tried using MongoCSharpDriver In statement and Builders.Filter.In and other variations.



An example error would be as follows. This is the code that is used.



List<Asset> assetList = (await mongoDb.GetCollection<Asset>().FindAsync(
asset => extractAssetsFromContentService.ExtractAssetFromDraftContent(contentAsMarkdown)
.Any(extractedAsset => extractedAsset.AssetId == asset.Id))).ToList();


System.ArgumentException : Unsupported filter: Any(value(System.Collections.Generic.List`1[DocWorks.Common.Transformation.Model.ExtractedAssetModel]).Where(({document}{AssetId} == {document}{_id}))).



this would be the same error except the Any would be 'Contains' when using contains instead of any. Similar to a distribution i cannot bring the assets into local memory. All entities share the same base class which Stores the Ids as follows:



 [BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }









share|improve this question
























  • Perhaps show a document sample a which you expect to match and the values you are expecting to match against. Also please include any actual logged errors. For completeness, please confirm if you are actually connecting to MongoDB and not CosmosDB with MongoDB emulation. The "list of strings" might be another different issue depending on what is actually stored in Id, but one problem at a time for now.
    – Neil Lunn
    Nov 21 at 0:09










  • i am trying to match 2 24 digit hex strings; BsonType.ObjectId. The list contains these and the Distribution Id is also a hex string. If you need a complete example data of a distribution i can provide but the only relevant parts are the Ids in this query. The is active and status checks are just searching for non deleted distributions. I can confirm that we are using MongoDb not CosmosDb. @NeilLunn
    – Matt Cooper
    Nov 21 at 10:14










  • @NeilLunn do you require any other information. If i missed anything apologies just point it out for me
    – Matt Cooper
    Nov 21 at 11:07
















3














i have seen other threads for this kind of question but none of the highlighted answers work for me.



The piece of code that throws the error is this



List<Distribution> distributionPublishQueueList = (mongoDb.GetCollection<Distribution>().Find(Builders<Distribution>.Filter.And(
Builders<Distribution>.Filter.Where(x => x.Status == EntityStatus.Ok),
Builders<Distribution>.Filter.Where(x => x.IsActive),
Builders<Distribution>.Filter.Where(x => distinctDistributionIdInPublishQueueList.Contains(x.Id))))).ToList();


The original code was this:



List<Distribution> distributionPublishQueueList = 
(await mongoDb.GetCollection<Distribution>()
.FindAsync(x => x.Status == EntityStatus.Ok
&& x.IsActive
&& distinctDistributionIdInPublishQueueList.Contains(x.Id)))
.ToList();


but i tried to make it more mongo friendly. Both pieces of code above are the same. The list distinctDistributionIdInPublishQueueList is a list of distribution Id's which are strings. So i am trying to find all distributions which Id is inside of that list + the other 2 filters. When i use the contains inside of the filter definition it throws an Unsupported filter exception. But the following code works because i bring the list into local memory and use LINQ against it:



List<Distribution> distributionPublishQueueList = (await mongoDb.GetCollection<Distribution>().FindAsync(x => x.Status == EntityStatus.Ok && x.IsActive)).ToList();
distributionPublishQueueList = distributionPublishQueueList.Where(x => distinctDistributionIdInPublishQueueList.Contains(x.Id)).ToList();


I need to be able to not do this in local memory due to the amount of Distributions that are present in the database. Is there a workaround to using Contains and Any. I have also tried using MongoCSharpDriver In statement and Builders.Filter.In and other variations.



An example error would be as follows. This is the code that is used.



List<Asset> assetList = (await mongoDb.GetCollection<Asset>().FindAsync(
asset => extractAssetsFromContentService.ExtractAssetFromDraftContent(contentAsMarkdown)
.Any(extractedAsset => extractedAsset.AssetId == asset.Id))).ToList();


System.ArgumentException : Unsupported filter: Any(value(System.Collections.Generic.List`1[DocWorks.Common.Transformation.Model.ExtractedAssetModel]).Where(({document}{AssetId} == {document}{_id}))).



this would be the same error except the Any would be 'Contains' when using contains instead of any. Similar to a distribution i cannot bring the assets into local memory. All entities share the same base class which Stores the Ids as follows:



 [BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }









share|improve this question
























  • Perhaps show a document sample a which you expect to match and the values you are expecting to match against. Also please include any actual logged errors. For completeness, please confirm if you are actually connecting to MongoDB and not CosmosDB with MongoDB emulation. The "list of strings" might be another different issue depending on what is actually stored in Id, but one problem at a time for now.
    – Neil Lunn
    Nov 21 at 0:09










  • i am trying to match 2 24 digit hex strings; BsonType.ObjectId. The list contains these and the Distribution Id is also a hex string. If you need a complete example data of a distribution i can provide but the only relevant parts are the Ids in this query. The is active and status checks are just searching for non deleted distributions. I can confirm that we are using MongoDb not CosmosDb. @NeilLunn
    – Matt Cooper
    Nov 21 at 10:14










  • @NeilLunn do you require any other information. If i missed anything apologies just point it out for me
    – Matt Cooper
    Nov 21 at 11:07














3












3








3







i have seen other threads for this kind of question but none of the highlighted answers work for me.



The piece of code that throws the error is this



List<Distribution> distributionPublishQueueList = (mongoDb.GetCollection<Distribution>().Find(Builders<Distribution>.Filter.And(
Builders<Distribution>.Filter.Where(x => x.Status == EntityStatus.Ok),
Builders<Distribution>.Filter.Where(x => x.IsActive),
Builders<Distribution>.Filter.Where(x => distinctDistributionIdInPublishQueueList.Contains(x.Id))))).ToList();


The original code was this:



List<Distribution> distributionPublishQueueList = 
(await mongoDb.GetCollection<Distribution>()
.FindAsync(x => x.Status == EntityStatus.Ok
&& x.IsActive
&& distinctDistributionIdInPublishQueueList.Contains(x.Id)))
.ToList();


but i tried to make it more mongo friendly. Both pieces of code above are the same. The list distinctDistributionIdInPublishQueueList is a list of distribution Id's which are strings. So i am trying to find all distributions which Id is inside of that list + the other 2 filters. When i use the contains inside of the filter definition it throws an Unsupported filter exception. But the following code works because i bring the list into local memory and use LINQ against it:



List<Distribution> distributionPublishQueueList = (await mongoDb.GetCollection<Distribution>().FindAsync(x => x.Status == EntityStatus.Ok && x.IsActive)).ToList();
distributionPublishQueueList = distributionPublishQueueList.Where(x => distinctDistributionIdInPublishQueueList.Contains(x.Id)).ToList();


I need to be able to not do this in local memory due to the amount of Distributions that are present in the database. Is there a workaround to using Contains and Any. I have also tried using MongoCSharpDriver In statement and Builders.Filter.In and other variations.



An example error would be as follows. This is the code that is used.



List<Asset> assetList = (await mongoDb.GetCollection<Asset>().FindAsync(
asset => extractAssetsFromContentService.ExtractAssetFromDraftContent(contentAsMarkdown)
.Any(extractedAsset => extractedAsset.AssetId == asset.Id))).ToList();


System.ArgumentException : Unsupported filter: Any(value(System.Collections.Generic.List`1[DocWorks.Common.Transformation.Model.ExtractedAssetModel]).Where(({document}{AssetId} == {document}{_id}))).



this would be the same error except the Any would be 'Contains' when using contains instead of any. Similar to a distribution i cannot bring the assets into local memory. All entities share the same base class which Stores the Ids as follows:



 [BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }









share|improve this question















i have seen other threads for this kind of question but none of the highlighted answers work for me.



The piece of code that throws the error is this



List<Distribution> distributionPublishQueueList = (mongoDb.GetCollection<Distribution>().Find(Builders<Distribution>.Filter.And(
Builders<Distribution>.Filter.Where(x => x.Status == EntityStatus.Ok),
Builders<Distribution>.Filter.Where(x => x.IsActive),
Builders<Distribution>.Filter.Where(x => distinctDistributionIdInPublishQueueList.Contains(x.Id))))).ToList();


The original code was this:



List<Distribution> distributionPublishQueueList = 
(await mongoDb.GetCollection<Distribution>()
.FindAsync(x => x.Status == EntityStatus.Ok
&& x.IsActive
&& distinctDistributionIdInPublishQueueList.Contains(x.Id)))
.ToList();


but i tried to make it more mongo friendly. Both pieces of code above are the same. The list distinctDistributionIdInPublishQueueList is a list of distribution Id's which are strings. So i am trying to find all distributions which Id is inside of that list + the other 2 filters. When i use the contains inside of the filter definition it throws an Unsupported filter exception. But the following code works because i bring the list into local memory and use LINQ against it:



List<Distribution> distributionPublishQueueList = (await mongoDb.GetCollection<Distribution>().FindAsync(x => x.Status == EntityStatus.Ok && x.IsActive)).ToList();
distributionPublishQueueList = distributionPublishQueueList.Where(x => distinctDistributionIdInPublishQueueList.Contains(x.Id)).ToList();


I need to be able to not do this in local memory due to the amount of Distributions that are present in the database. Is there a workaround to using Contains and Any. I have also tried using MongoCSharpDriver In statement and Builders.Filter.In and other variations.



An example error would be as follows. This is the code that is used.



List<Asset> assetList = (await mongoDb.GetCollection<Asset>().FindAsync(
asset => extractAssetsFromContentService.ExtractAssetFromDraftContent(contentAsMarkdown)
.Any(extractedAsset => extractedAsset.AssetId == asset.Id))).ToList();


System.ArgumentException : Unsupported filter: Any(value(System.Collections.Generic.List`1[DocWorks.Common.Transformation.Model.ExtractedAssetModel]).Where(({document}{AssetId} == {document}{_id}))).



this would be the same error except the Any would be 'Contains' when using contains instead of any. Similar to a distribution i cannot bring the assets into local memory. All entities share the same base class which Stores the Ids as follows:



 [BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }






c# .net mongodb .net-core mongodb-query






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 11:06

























asked Nov 20 at 16:52









Matt Cooper

162




162












  • Perhaps show a document sample a which you expect to match and the values you are expecting to match against. Also please include any actual logged errors. For completeness, please confirm if you are actually connecting to MongoDB and not CosmosDB with MongoDB emulation. The "list of strings" might be another different issue depending on what is actually stored in Id, but one problem at a time for now.
    – Neil Lunn
    Nov 21 at 0:09










  • i am trying to match 2 24 digit hex strings; BsonType.ObjectId. The list contains these and the Distribution Id is also a hex string. If you need a complete example data of a distribution i can provide but the only relevant parts are the Ids in this query. The is active and status checks are just searching for non deleted distributions. I can confirm that we are using MongoDb not CosmosDb. @NeilLunn
    – Matt Cooper
    Nov 21 at 10:14










  • @NeilLunn do you require any other information. If i missed anything apologies just point it out for me
    – Matt Cooper
    Nov 21 at 11:07


















  • Perhaps show a document sample a which you expect to match and the values you are expecting to match against. Also please include any actual logged errors. For completeness, please confirm if you are actually connecting to MongoDB and not CosmosDB with MongoDB emulation. The "list of strings" might be another different issue depending on what is actually stored in Id, but one problem at a time for now.
    – Neil Lunn
    Nov 21 at 0:09










  • i am trying to match 2 24 digit hex strings; BsonType.ObjectId. The list contains these and the Distribution Id is also a hex string. If you need a complete example data of a distribution i can provide but the only relevant parts are the Ids in this query. The is active and status checks are just searching for non deleted distributions. I can confirm that we are using MongoDb not CosmosDb. @NeilLunn
    – Matt Cooper
    Nov 21 at 10:14










  • @NeilLunn do you require any other information. If i missed anything apologies just point it out for me
    – Matt Cooper
    Nov 21 at 11:07
















Perhaps show a document sample a which you expect to match and the values you are expecting to match against. Also please include any actual logged errors. For completeness, please confirm if you are actually connecting to MongoDB and not CosmosDB with MongoDB emulation. The "list of strings" might be another different issue depending on what is actually stored in Id, but one problem at a time for now.
– Neil Lunn
Nov 21 at 0:09




Perhaps show a document sample a which you expect to match and the values you are expecting to match against. Also please include any actual logged errors. For completeness, please confirm if you are actually connecting to MongoDB and not CosmosDB with MongoDB emulation. The "list of strings" might be another different issue depending on what is actually stored in Id, but one problem at a time for now.
– Neil Lunn
Nov 21 at 0:09












i am trying to match 2 24 digit hex strings; BsonType.ObjectId. The list contains these and the Distribution Id is also a hex string. If you need a complete example data of a distribution i can provide but the only relevant parts are the Ids in this query. The is active and status checks are just searching for non deleted distributions. I can confirm that we are using MongoDb not CosmosDb. @NeilLunn
– Matt Cooper
Nov 21 at 10:14




i am trying to match 2 24 digit hex strings; BsonType.ObjectId. The list contains these and the Distribution Id is also a hex string. If you need a complete example data of a distribution i can provide but the only relevant parts are the Ids in this query. The is active and status checks are just searching for non deleted distributions. I can confirm that we are using MongoDb not CosmosDb. @NeilLunn
– Matt Cooper
Nov 21 at 10:14












@NeilLunn do you require any other information. If i missed anything apologies just point it out for me
– Matt Cooper
Nov 21 at 11:07




@NeilLunn do you require any other information. If i missed anything apologies just point it out for me
– Matt Cooper
Nov 21 at 11:07

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397808%2fmongo-db-unsupported-filter-type-when-using-any-or-contains-are-there-any%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397808%2fmongo-db-unsupported-filter-type-when-using-any-or-contains-are-there-any%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga