We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I was trying to query sub-documents in an array. This is the code I'm running:
var jsData = require('js-data'); var MemoryAdapter = require('js-data-memory'); jsData.utils.Promise = require('bluebird'); var adapter = new MemoryAdapter(); var container = new jsData.Container({ mapperDefaults: { } }); container.registerAdapter('memory', adapter, { 'default': true }); var LangStringSchema = new jsData.Schema({ type: 'object', properties: { lang: { type: 'string' }, value: { type: 'string' } }, required: ['lang', 'value'] }); var FoodCategorySchema = new jsData.Schema({ type: 'object', properties: { names: { type: 'array', items: LangStringSchema }, parentID: { type: 'string' }, } }); container.defineMapper('food-categories', { schema: FoodCategorySchema, relations: { belongsTo: { 'food-categories': { foreignKey: 'parentID', localField: 'parentCategory' } }, hasMany: { 'food-categories': { foreignKey: 'id', localField: 'childrenCategories' } } } }); var c1 = container.create('food-categories', { names: [ { value: 'Carne', lang: 'pt' }, { value: 'Meat', lang: 'en' } ] }); c1.then(function(cat) { container.create('food-categories', { names: [ { value: 'Frango', lang: 'pt' }, { value: 'Chicken', lang: 'en' }, ], parentID: cat['id'] }); container.create('food-categories', { names: [ { value: 'Vaca', lang: 'pt' }, { value: 'Cow', lang: 'en' } ], parentID: cat['id'] }); container.create('food-categories', { names: [ { value: 'Porco', lang: 'pt' }, { value: 'Pork', lang: 'en' } ], parentID: cat['id'] }); }); setTimeout(function() { container.findAll('food-categories', { where: { 'names.value': { '==': 'Cow' }, 'names.lang': { '==': 'en' } } }).then(function(cats) { console.log(cats); }); }, 200);
I was expecting the output to be an array containing a single document. But, instead, I got an empty array.
Use the following package.json:
package.json
{ "name": "test-jsdata", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "bluebird": "^3.5.3", "js-data": "^3.0.5", "js-data-memory": "^0.1.4", "js-data-rethinkdb": "^3.0.0" } }
The content of index.js is the code snippet I included in the description section.
index.js
The text was updated successfully, but these errors were encountered:
@echo66 does this help? https://www.js-data.io/docs/query-syntax#section--isectnotempty-
Sorry, something went wrong.
Hey, @crobinson42 !
In that page, there are no examples regarding sub-document queries.
EDIT: In 2.9 docs, there is a reference to nested fields. But I can't access the filter method in a container, right?
So what you're trying to accomplish, at the most basic example, is demonstrated here: https://runkit.com/crobinson42/js-data-532-query-sub-documents
Which is not working as expected :-(
No branches or pull requests
Uh oh!
There was an error while loading. Please reload this page.
Description
I was trying to query sub-documents in an array. This is the code I'm running:
I was expecting the output to be an array containing a single document. But, instead, I got an empty array.
Environment
js-data version:
node or browser version:
operating system:
Steps to reproduce
Use the following
package.json
:The content of
index.js
is the code snippet I included in the description section.The text was updated successfully, but these errors were encountered: