Unable to find value using variable as field name in find() method within Mongo Shell - mongo-shell

I've executed the following command in mongo shell:
db.perscoll.insert({CT:{English:{genre:[{name:varGenre}]}}})
Now, i want to find whether genre for 'English' exists in the collection or not using find(), which will return either 0(false) or 1(true).
db.perscoll.find({'CT.English.genre.name':varGenre}).count();
The above command returns me 1(true), but when i try to execute the same command using variable as mentioned below, it returns 0 .
var eType = 'CT';
var lang = 'English';
var varGenre = 'Action';
var gnrNameChk = {};
gnrNameChk[eType+'.'+lang+'.genre.name'] = '';
print(gnrNameChk);
db.perscoll.find({gnrNameChk:varGenre}).count();
What can be the problem? how to tackle this? I'm not getting any way to sort this out.

Try the following:
var eType = 'CT';
var lang = 'English';
var varGenre = 'Action';
var gnrNameChk = {};
gnrNameChk[eType+'.'+lang+'.genre.name'] = varGenere;
print(gnrNameChk);
db.perscoll.find(gnrNameChk).count();
Hope that helps you!!!

Related

Dartap Search Criteria

I'm using dartdap to query ldap for certain records.
Dartap v0.6.2 https://pub.dev/packages/dartdap
Dart SDK v.2.17.1
I can connect successfully to ldap, but I can't figure out how to pass search criteria. Let's say I want to retrieve records for cn (common name) containing Joe, cn=Joe*. How would I pass cn=Joe* to dartapp?
The following is a snippet from the credentials and connection section.
var filter = Filter.present('objectClass');
var attrs = ['dn', 'cn', 'objectClass']; //define returned attributes, but where do I pass a filter?
Future example() async {
var host = 'hostname';
var bindDN = 'user#domain';
var password = 'password';````
I found a way to filter. In case anyone else has the same issue, the following works:
// original
var filter = Filter.present('objectClass');
// change to
var filter = Filter.substring('cn', 'Joe*');

Search help is not giving exact results in UI5

I have written code for search fields in ui5 controllers files, But the search field is not giving expected output when I pasted particular column value in input search field. Instead if I type the value in search field it is giving exact output.
I have used livechange event. I also tried with search event but unable to get the output.
I am using odata services.
Below is the controller file code:
onSearch: function(oEvt) {
// add filter for search
var aFilters = [];
var sQuery = oEvt.getSource().getValue();
if (sQuery && sQuery.length > 0) {
var filter = new Filter("UNIQUE_ID", sap.ui.model.FilterOperator.EQ, sQuery);
aFilters.push(filter);
}
// update list binding
var list = this.byId("orderTable");
var binding = list.getBinding("items");
binding.filter(aFilters);
}
View code:
Label class="sapUiMediumMarginTop" text="Unique Id"
SearchField width="150px" class="sapUiSmallMargin" liveChange="onSearch"
Please suggest me if I am missing anything.
Maybe this example can help you out? I tested your code with some random data and it worked for me.
onSearch: function(oEvent) {
var sQuery = oEvent.getParameter("query");
var oFilter1 = new Filter("Name", FilterOperator.Contains, sQuery);
var oFilter2 = new Filter("Age", FilterOperator.Contains, sQuery);
var arrFilter = new Filter([oFilter1, oFilter2], false);
// filter binding
var oList = this.byId("idList");
var oBinding = oList.getBinding("items");
oBinding.filter(arrFilter);
},

What is the relationship between real collections' names and those in file system

I use MongoDB 3.0 with WiredTiger storage engine.
When I checked my Mongo files in dbPath, I saw the names of the files with the formats as below:
collection-0--4989330656807016483.wt
collection-2--4989330656807016483.wt
collection-4--4989330656807016483.wt
.
.
.
How can I know the relationship between these file names and real collections' names except the way of data size??
I have found the way that the command "db.collection.stats()" would show the wiredTiger.metadata.uri which defines the relationship between the collection's logical name and file name the command
A simple script to find the collection name for a given file name:
function findInDb(dbName, collectionIdToFind) {
var dbToSearch = db.getSiblingDB(dbName);
var collectionNames = dbToSearch.getCollectionNames();
for(var i = 0; i < collectionNames.length; i++){
var name = collectionNames[i];
var stats = dbToSearch.getCollection(name).stats();
var uri = stats.wiredTiger.uri;
if (uri.endsWith(collectionIdToFind))
return name;
}
return null;
}
function findInAllDbs(collectionIdToFind) {
var adminDb = db.getSiblingDB("admin");
var dbList = adminDb.runCommand({ "listDatabases": 1 }).databases;
for (var i in dbList) {
var found = findInDb(dbList[i].name, collectionIdToFind);
if (found != null) {
return dbList[i].name + "." + found;
}
}
return "(not found)";
}
print(findInAllDbs("collection-20-571885508699163146")); // filename in crash report, etc.
Use this
db.getCollection('collection_name').stats()

nDepend - how to modify "JustMyCode" queries using nDepend API?

My goal is to modify "JustMyCode" queries using nDepend API. I am using code like:
var justMyCodeGroup = prj.CodeQueries.CodeQueriesSet.ChildGroups.Single(x => x.Name.Contains("JustMyCode"));
var originalQuery = justMyCodeGroup.ChildQueries
.Single(x => x.QueryString.Contains("Discard generated Types from JustMyCode"));
var changedQuery = originalQuery.Controller.CreateQuery(originalQuery.IsActive,
query,
originalQuery.
DisplayStatInReport,
originalQuery.DisplayListInReport,
originalQuery.DisplaySelectionViewInReport,
originalQuery.IsCriticalRule);
var justMyCodeGroupWithModifiedQuery = justMyCodeGroup.ReplaceQuery(originalQuery, changedQuery);
prj.CodeQueries.CodeQueriesSet.ReplaceGroup(justMyCodeGroup, justMyCodeGroupWithModifiedQuery);
However, when I run the code above I get ArgumentException with message:
newGroup.Controller is different than this groupOfGroups.Controller
Any help ?
Update 1:
I also tried code:
var justMyCodeGroup = prj.CodeQueries.CodeQueriesSet.ChildGroups.Single(x => x.Name.Contains("JustMyCode"));
var originalQuery = justMyCodeGroup.ChildQueries
.Single(x => x.QueryString.Contains("Discard generated Types from JustMyCode"));
var changedQuery = originalQuery.Controller.CreateQuery(originalQuery.IsActive,
query,
originalQuery.
DisplayStatInReport,
originalQuery.DisplayListInReport,
originalQuery.DisplaySelectionViewInReport,
originalQuery.IsCriticalRule);
var justMyCodeGroupWithModifiedQuery = justMyCodeGroup.ReplaceQuery(originalQuery, changedQuery);
var newQueries = new List<IQuery>();
foreach (var q in justMyCodeGroup.ChildQueries)
{
if (q.QueryString.Contains("Discard generated Types from JustMyCode"))
{
continue;
}
newQueries.Add(prj.CodeQueries.CodeQueriesSet.Controller.CreateQuery(q.IsActive, q.QueryString,
q.DisplayStatInReport, q.DisplayListInReport, q.DisplaySelectionViewInReport, q.IsCriticalRule));
}
newQueries.Add(prj.CodeQueries.CodeQueriesSet.Controller.CreateQuery(originalQuery.IsActive, query, originalQuery.DisplayStatInReport, originalQuery.DisplayListInReport, originalQuery.DisplaySelectionViewInReport, originalQuery.IsCriticalRule));
var newGroup = prj.CodeQueries.CodeQueriesSet.Controller.CreateGroup(justMyCodeGroup.Name,
justMyCodeGroup.IsActive, justMyCodeGroup.ShownInReport, newQueries, new List<IGroup>());
prj.CodeQueries.CodeQueriesSet.RemoveGroup(justMyCodeGroup);
prj.CodeQueries.CodeQueriesSet.AddGroup(newGroup);
Right now, RemoveGroup throws exception:
this group of groups doesn't contain groupToRemove.
Update 2:
And I also wonder, why does this code return false ?
var justMyCodeGroup = prj.CodeQueries.CodeQueriesSet.ChildGroups.Single(x => x.Name.Contains("JustMyCode"));
prj.CodeQueries.CodeQueriesSet.ContainsGroup(justMyCodeGroup)
Refer to the PowerTools source file:
$NDependInstallDir$\NDepend.PowerTools.SourceCode\CQL2CQLinq\CQL2CQLinqPowerTool.cs
This PowerTools convert code queries written with old CQL syntax into code queries written with new CQLinq syntax, hence it loads the queries set from a project, update CQL queries, and then save the new queries set in the project.
The queriesController is gathered this way...
var queriesSet = project.CodeQueries.CodeQueriesSet;
var queriesController = queriesSet.Controller;
... and then used this way to modify the queries set:
queriesController.DoUpdateQueryObject(query, newQuery);

In linq-to-entities, how to return objects with a filtered list of children?

I have the following model
The first step is to select all the ProductionBlock with
var blocks = context.ProductionBlocks;
How can I combine the ProductionLog that has no end time with the ProductionBlock?
I tried to do it using a reverse lookup like
var blocks = context
.ProductionLogs
.Include("FK_ProductionLog_ProductionBlock")
.Where(log => log.EndTime == null).Select(log => log.ProductionBlock)
.Union(context.ProductionBlocks);
But the blocks don't contains any ProductionLogs. How can I achieve that?
Let me know if i am off base, but you would want.
var logs = (
from pl in context.ProductionLogs.Include("ProductionBlock")
where pl.EndTime == null
select pl);
You would then have a list of logs and blocks.
var blocks = logs.SelectMany(x=>x.ProductionBlock)