Nick
Nick

Reputation: 4092

Does anyone have a working example of JSON insert/select in OrientDB?

Select query doesn't work for JSON in OrientDB. Can someone provide with a working example showcasing two things:

  1. Inserting JSON data correctly

  2. Querying JSON data

Thanks!

Upvotes: 7

Views: 6882

Answers (3)

bondkn
bondkn

Reputation: 450

1.Use "content" to implement JSON insert.

For Example-
insert into Person content {"name":"nawab","age":25}

for this to run,you must have prior configuration as-
1.Create a Vertex by-

create class Person extends V    

2.Then Create Property name and age

create property Person.name string
create property Person.age integer

Upvotes: 4

K.K
K.K

Reputation: 2657

Here you go! I have been trying to figure this out for a while now and finally got it to work. :)

Run the following sql commands as displayed:

create class EXAMPLE

/* The trick is: Do not 'CREATE' the property with any type */

insert into EXAMPLE (my_prop) values ({"name": "James", "age": 23})
insert into EXAMPLE (my_prop) values ({"name": "Harden", "age": 24})

/* Fetch the fields inside the JSON */
select my_prop.name from example
select my_prop.age from example where my_prop.name like 'James'

I read this example from the book: Getting Started with OrientDB By Claudio Tesoriero

Hope it helps!

Upvotes: 3

Lvca
Lvca

Reputation: 9060

This question continues in the OrientDB group here. Have you tried if everything work?

Upvotes: 1

Related Questions