what can i pass in returns ( ) to solve the problem - loops

enter image description here i try my best , but in returns .....what should i pass.
o/p i want
{
"9856325896" : "199",
"9856334649" : "599"
}
{ "phone" : "balance" } (Example) when i call function details , i want these type of output. please help me to solve problem ......thanks in advance

Related

db.collection.find({$text :{$search : "some text"}}) is not returning anything

I have a mongo database collection with name shopping here
{
"_id":{"$oid":"5fcbaddafac0e534d086696c"},
"imagePath":"https://5.imimg.com/data5/UU/DQ/MY-54426657/tata-salt-packet-500x500.png",
"title":"Tata salt packet",
"description":"used for making food!!",
"price":10,"__v":0
}
when i try to search the title in the collection with the command
db.shopping.find({$text :{$search : "Tata salt packet"}})
nothing is comming in the output it just exits and waits for the next command
i already done indexing by this command
db.shopping.createIndex( { title: "text" } )
and got this as output
{
"numIndexesBefore" : 2,
"numIndexesAfter" : 2,
"note" : "all indexes already exist",
"ok" : 1
}
can anyone tell me whats the problem why i am not getting the output
here is how it looks
thanks
Can you try Exact Phrase like below,
db.shopping.find( { $text: { $search: "\"Tata salt packet\"" } } );

Firebase.util.NormalizedCollection merge multiple paths

I would like to know if it is possible with Firebase.util.NormalizedCollection to merge 3 paths or more who depends on each other. On firebase doc it said that the best practice with our datas is to have flattened data as possible, so I have that :
question :
uniqueIdqestion1 :
myquestion : "ma question",
answers : {
uniqueIdanswer1 : true,
uniqueIdanswer54 : true
}
answer :
uniqueIdanswer1 :
my_answer : "my answer",
people : {
uniqueIdpeople1 : true
}
people
uniqueIdpeople1 :
name : "pedra"
With Firebase.util.NormalizedCollection, I would like to list all the answer for my question and have an array like that :
key_answer : uniqueIdanswer,
my_answer : "ma response",
name : "pedra"
I tried to have something like that with this code :
var ref = firebase.database().ref();
var nc = new firebase.util.NormalizedCollection(
ref.child('questions/' + $state.params.chatId + '/answers'),
[ref.child('answers'), 'widget2'], // B path
... ??? // C path
)
.select('widget2.my_answer', ???).ref();
$scope.reponses = $firebaseArray(nc);
But I can't still understand how to merge the B and C path. Maybe it's because C doesn't refer directly to the main path, I don't understand because something is missing for me in my mind ... Please can you help me with that ?

How to get some documents of array in MongoDB

I have collection "users" where username , password,questions are stored . "questions" is an array of documents . I would like to get all users with some questions i.e username , password and an array of questions (some part) How can i do that from console or java ?
Here i want to get username , password and first document of questions which is {question:"dawdaw",answered:0}
You can use slice like this
db.users.find({},{"questions":{$slice:1}})
Hope it will help
Use $elemMatch projection to get the desired result. The following find() operation queries for all documents where the $elemMatch projection returns only the first matching element of the questions array where the question field has a value of "dawdaw" and answered has 0 value:
db.users.find({},
{
"username": 1, "password": 1,
"questions": {
"$elemMatch": {
"question" : "dawdaw",
"answered" : 0
}
}
}
);
From the sample given, the operation returns the following document:
/* 0 */
{
"_id" : ObjectId("561a84ffaa233b38d803509a"),
"username" : "asd#mail.ru",
"password" : "asd",
"questions" : [
{
"question" : "dawdaw",
"answered" : 0
}
]
}

Create temp values in AngularJS

In angular the following happened to me
function(){
$scope.varObj = {"name" : "john" , "age" : "20" };
$scope.tempVar1 = $scope.varObj;
$scope.tempVar2 = $scope.varObj ;
}
Now if i change tempVar2 automatically the value of tempVar1 is changed.
function(){
$scope.varObj = {"name" : "john" , "age" : "20" };
$scope.tempVar1 = $scope.varObj;
$scope.tempVar2 = $scope.varObj;
$scope.tempVar2.name = "mathews";
console.log($scope.tempVar1.name);
}
The output should be "john" because i am changing the value of tempVar2 not the tempVar1. But to the surprise the output is "mathews".
I tried both angular.copy and angular.extend but both produce the same output.
Can someone please help
I don't see any reason for it to not work with angular.copy
Heres' a fiddle with
demo
It's hapening becuase of two way binding
Try like this
$scope.tempVar1 = angular.copy($scope.varObj);
Use angular.copy() for it
By default only reference copy with assignment operator = which mean sharing the same memory space so if you change in any of the two object it will reflect into second one as well.
angular.copy() will create deep copy of the object
DOC:-
Creates a deep copy of source, which should be an object or an array.
$scope.varObj = {"name" : "john" , "age" : "20" };
$scope.tempVar1 = angular.copy($scope.varObj);
$scope.tempVar2 = angular.copy($scope.varObj);
$scope.tempVar2.name = "mathews";
console.log($scope.tempVar1.name);

Sorting an arraycollection with a numeric value coming from 2 diffrent fields

Hi guys I need to sort an arraycollection. the problem is that my array is combined from two diffrent arrays, in one the age field is called "AGE", and in the other the age is called "MYAGE".
Now I need to sort the combined array according to age but I got two fields with diffrent names. I can go through the array and change all "MYAGE" to "AGE" but i was wondering if theres maybe a way to sort the array in its current status?
Thanks ahead
Say you have an ArrayCollection called myCollection. I hope the following will solve your request for that:
private function compareItems(a:Object, b:Object, fields:Array = null):int
{
var firstValue:Number = "AGE" in a ? a["AGE"] : a["MYAGE"];
var secondValue:Number = "AGE" in b ? b["AGE"] : b["MYAGE"];
if (firstValue == secondValue)
return 0;
return firstValue > secondValue ? 1 : -1;
}
…
var sort:ISort = new Sort();
sort.compareFunction = compareItems;
myCollection.sort = sort;
myCollection.refresh();

Resources