Usergrid query on unknown sub properties - apache

I'm trying to query a collection of data with entities that contain the "related" property:
...,{ related :
{ global: [{name: "foo"}, {name: "bar"}] },
{ local: [{name: "bar"}] },
{ random: [{name: "foo"}] },
{ dingbat: [{name: "baz"}] },
}
I want to write a query which selects all entities which have name="foo" anywhere within the related property.
I can do this just fine:
select * where related.global.name='foo'
However there could be any number of keys within the "related" property so I can't just AND them all into a single query. Trying to do something like this (which doesn't work)
select * where related.*.name='foo'
Is there any way to achieve this?

Not at this time. However, it is something we could consider for the future. We have ElasticSearch for indexing in our 2.1 platform and we can use the '_all' functionality from ES but we have not exposed that in Usergrid yet.

Related

Unique field types and specific GET-parameters for api calls in Apostrophe CMS

I have several questions about Apostrophe CMS:
Is it possible to add a unique field type in apostrophe-pieces? I can't find a way to do this.
Edit: I noticed that I wasn't specific enough. I want to make sure that there can't be two instances in the database with the same value in an added field. It should be something like an additional id. Is there an option for this? Maybe something like:
addFields: [
{
name: 'secondId',
label: 'Second ID',
type: 'string',
required: true,
unique: true
}
]
I want to access the apostrophe-headless api and get a specific element by passing a certain value of one of the created field types of the correspondent piece in a GET-parameter. Is something like this possible?
For example:
Piece:
module.exports = {
extend: 'apostrophe-pieces',
name: 'article',
label: 'Article',
pluralLabel: 'Articles',
restApi: {
safeFor: 'manage'
},
addFields: [
{
name: 'title',
label: 'Name',
type: 'string',
required: true
},
{
name: 'author',
label: 'Author',
type: 'string',
required: true
}
]
};
Desired api call for getting all articles which have strored "Jon" as author:
http://example.com/api/v1/article?author=Jon
Thank you very much in advance!
Custom field types
You can add custom field types at project level by extending apostrophe-schemas and adding the proper definition. You'll need to add a converter for server-side sanitization and a populator for the front-end of the form field.
You can follow the examples in Apostrophe's schema module, linked are the functions defining a float
https://github.com/apostrophecms/apostrophe/blob/0bcd5faf84bc7b05c51de7331b17f5929794f524/lib/modules/apostrophe-schemas/index.js#L1367
https://github.com/apostrophecms/apostrophe/blob/0bcd5faf84bc7b05c51de7331b17f5929794f524/lib/modules/apostrophe-schemas/public/js/user.js#L991
You would add your definitions in your project level lib/modules/apostrophe-schemas's index.js and public/js/user.js respectively.
Filtering
You can search your piece index for a string like Jon by adding ?search=jon to your query but more likely you want to filter pieces by the value of a join.
If you had piece types article and authors, you could have a joinByOne field in article's schema that lets you relate that article to an author piece. Then, by enabling pieceFilters you could filter directly on those joined properties.
A complete rundown of piecesFilters can be found here https://apostrophecms.org/docs/tutorials/intermediate/cursors.html#filtering-joins-browsing-profiles-by-market
I think you'd also need to mark that filter as safe for api use in your apostrophe-headless configuration https://github.com/apostrophecms/apostrophe-headless#filtering-products

MongoDB - Load a subset of documents for querying

I have a collection containing multiple clients, months, etc.
Each month I need to run a series of queries against the collection to retrieve metrics - basically a bunch of counts.
Most of those queries have the same 4 or 5 filters, with an additional 1-2 filters that change for each query.
//standard filters:
{ client: "ABC Corp",
environment: "Production",
device: "true",
registered: "true"
}
//special filters:
{ type: "typeA",
screen: "screen1" }
{ type: "typeA",
screen: "screen2" }
In MSSQL I would create a view containing the 4 standard filters, and query that view repeatedly, applying the additional 1-2 filters to retrieve the needed metrics.
Any suggestions about what MongoDB or basic JS approach I could use for this? My goal is to avoid hitting the collection over and over again with those same standard filters.
Thanks
V
You could use $out operator in aggregation framework to achieve this.
$out stage can output results into a new collection
For example:
db.collection.aggregate([
{
$match:
{
client: "ABC Corp",
environment: "Production",
device: "true",
registered: "true"
}
},
{
$out: "new_collection"
}
])
Then you can run your additional queries on the new_collection.
Your "view" collection will be recreated every time when you use it in $out stage but any indexes you defined on that collection will be left intact.

Query to retrieve defects from parent and children

I have inherited code that displays a graph of defects on a project. I have now took my project and split it into two projects, so that now there is a parent project and two children. The code (below) just accumulates the defects from the parent and does not include the data from the children.
snippet:
storeType: "Rally.data.lookback.SnapshotStore",
storeConfig: {
find: { _TypeHierarchy: "Defect", Children: null },
fetch: ["Severity", "State"], hydrate: ["Severity", "State"],
sort: { _ValidFrom: 1 },
filters: [{ property: "Project", value: context.getProject().ObjectID }, { property: "_TypeHierarchy", value: "Defect" }, { property: "Children", value: null}] },
So I'm pretty sure the problem is in this part "value: context.getProject().ObjectID" as it says to get the data from the current project (and not its children). How can I accomplish what I need?
Not sure if you're intending to get lookback (time series) data or current (WSAPI) data from Rally. Your code implies lookback so I will answer with that in mind.
You could try adding to your find clause (and removing the current Project filter):
"_ProjectHierarchy": { $in : [123] }
where 123 is the object id of your parent project. That should get defects from any projects that include you parent project in the hierarchy.
So Igor basically got it above, just writing as a post and not in a commet, this is the code that works - you can see why in the comments above. Please note - I did make one change over what he wrote, as when I used the "__At" it caused not all bugs to be counted - it looked like it only counted bugs since their last update time.
storeConfig: {
find: { _TypeHierarchy: "Defect", _ProjectHierarchy: context.getProject().ObjectID},
fetch: ["Severity", "State"], hydrate: ["Severity", "State"],
sort: { _ValidFrom: 1 },
},

Dojo store query with wildcard

I'm using a Dojo memory store (dojo/store/Memory). I would like to retrieve items based on a wildcard query but the query method doesn't seem to support wildcards. i.e. given the following items:
{ id: "apple", details: "fruit" }
{ id: "applemac", details: "computer" }
store.query({ id: "apple" }) returns the first row as expected, but store.query({ id: "apple*" }) returns nothing.
Does anyone know if it's possible to use wildcards and if so, how?
Thanks
You can use a RegExp object to do wildcard queries
store.query({id:new RegExp("apple*")})
Here's a JSFiddle

rally search user by first character

I want to realize the functionality that we can search the users' name by typing in the first character of their names. I need to use Javascript to create a custom html.
Is there anyone who has done this before could help me?
In the example from this repository, a user combobox Rally.ui.combobox.UserComboBox searches for matching values dynamically based on the first couple of characters.
This default functionality displays the expected values after the second character is entered.
var u = Ext.create('Rally.ui.combobox.UserComboBox',{
id: 'u',
project: project,
fieldLabel: 'select user',
listeners:{
ready: function(combobox){
this._onUserSelected(combobox.getRecord());
},
select: function(combobox){
this._onUserSelected(combobox.getRecord());
},
scope: this
}
});
this.add(u);
},
If you want to load all users (do not limit the selection to team members and editors of a specific project) you may use Rally.ui.combobox.Combobox instead of Rally.ui.combobox.UserComboBox, and set the model to User. But to workaround a default behavior where only the current user populates the combobox, use a filter that would filter in all users. In the example below ObjectID > 0 is used. This combobox will be populated by all users independently of the project picker. This fragment is not a part of a custom app example above:
{
xtype: 'rallycombobox',
fieldLabel: 'select project',
storeConfig: {
autoLoad: true,
model: 'User',
filters:[
{
property: 'ObjectID',
operator: '>',
value: 0
}
],
sorters: [
{
property: 'UserName',
direction: 'ASC'
}
]
}
}
You'll want to use the Web Services API. Here's how I would do it...
The API doesn't allow you to specify a placement of a character in the filter, but you can require that it exists somewhere in the name, that filter would look like:
[{
property : "FirstName",
operator : "contains",
value : "A" //Whatever letter you're looking to start with
}]
Now, once the store is loaded, use a second function to filter the records to only those which start with your character:
store.filterBy(function(item) {
return item.get("FirstName")[0] === "A";
});
Hope this helps :)