2

I'm using taffyDB to query my javascript objects. I have a database db(), where each item in the db has an attribute Test Field and an attribute Test_Field.

If I want to query all the items in db() for which the value of Test_Field is "test", the following works:

var dbQuery = db({ Test_Field:"test" }).get()

However, if I want to query all the items in db() for which the value of Test Field is "test", I cannot find any query that works. The following are my best attempts.

var dbQuery = db({ Test Field:"test" }).get()

var fieldName = "Test Field"
var dbQuery = db({ fieldName:"test" }).get()

var field = {}
field[name] = "Test Field"
var dbQuery = db({ field[name]:"test" }).get()

I want to grab the items where Test Field is "test" Any ideas how to query with a variable name so that I can check an attribute with space in its name like Test Field?

Thank you very much for your time. Let me know if I am being unclear or if you need anything else from me.

user95227
  • 1,853
  • 2
  • 18
  • 36

2 Answers2

3

Have you tried db().filter({"Test Field": "test"}); or var obj = {}; obj[fieldName] = "test"; db().filter(obj);

Aneesh
  • 579
  • 2
  • 5
  • 21
2
var fieldName = "Test Field"
var dbQuery = db({ fieldName:"test" }).get()

The above does not work because the object assigns the value "test" to the key "fieldname" and your object looks like this :

{fieldname:"test"} 

and not

{"Test Field":"test"}

Try Doing :

fieldName = "Test Field";
var field = {};
field[fieldName] = "test";
var dbQuery = db(field).get();
Aniruddha Gohad
  • 253
  • 3
  • 21