asked    Rose     2018-10-22       javascript       123 view        1 Answer

[SOLVED] Retrive a field which has array of objects(ref) using nodejs

Im having mongo(mongoose) collection called "asserts" and "users". Having list of documents in "asserts" collection. Now while adding a user I need to select multiple "asserts". So need to set "ref" to asserts collection.

Below is my modal

 asserts_list: {
    type: [Schema.Types.ObjectId],
    ref: "asserts"   },

POST operation is working fine (i.e) I can add multiple object IDs in Mongoose in array. But while performing list using AppComp.find({}) with populate, asserts_list is returning empty array([]).

Help me to retrieve array of object ids in find({}) using nodejs.

  1 Answer  

        answered    Diana     2018-10-22      

You need to define properly

asserts_list: [{
    type: Schema.Types.ObjectId,
    ref: "asserts"   }],

and then use populate function

Your Answer

 2018-10-22         Alexander

Django saving modelformset_factory

When saving the formset, it is not validating and respecting the model fields that I have made unique and therefore renders an Integrity Error should I duplicate fields deliberately to test it.My guess is that the formsets themselves validate correctly, but as the unique field is something I have to assign during the save(commit=False) process it never gets validated. Does that make sense?Is there something I am missing please?My code:class ClientCreate(LoginRequiredMixin, FormView): def dispatch(self, *args, **kwargs): = Case.objects.get(pk=kwargs['case...
 django                     1 answers                     51 view
 2018-10-22         Woodrow

Making a matrix in python 3 without numpy using inputs

I want to have two inputs : a,b or x,y whatever...When the user inputs say,3 5Then the shell should print a matrix with 3 rows and 5 columns also it should fill the matrix with natural numbers( number sequence starting with 1 and not 0).Example:: IN :2 2OUT:[1,2] [3,4] If your objective is only to get the output in that formatn,m=map(int,input().split())count=0for _ in range(0,n): list=[] while len(list) > 0 : list.pop() for i in range(count,count+m): list.append(i) count+=1 print(list) [XXX]I am going to give a try without using numpy...
 python-3.x                     3 answers                     55 view
 2018-10-22         Rex

Why assigning a function as variable is faster in Python

Today I observed an interesting behavior using Python.def f(): ls1 = [] for x in range(1000000): ls1.append(x)%timeit f()77.2 ms ± 1.83 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)And tested a second function.def f2(): ls1 = [] lsa = ls1.append for x in range(1000000): lsa(x) %timeit f2()56 ms ± 566 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)Assigning append to a variable was faster than using append inside the loop.Why the second function is faster? Because in the second function, you have the reference to the m...
 python-3.x                     2 answers                     59 view