Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documents with random fields name #5

Closed
njordr opened this issue Jul 11, 2016 · 2 comments
Closed

documents with random fields name #5

njordr opened this issue Jul 11, 2016 · 2 comments
Labels

Comments

@njordr
Copy link

njordr commented Jul 11, 2016

Hi.

How can I map a document like this?

{
"_id" : "locations_names",
"1" : "California - US",
"2" : "New Jersey - US",
"3" : "Singapore - SG",
"4" : "Texas - US",
"5" : "Rotterdam - NL",
"6" : "London - UK",
"7" : "Dallas - US",
"8" : "Seattle - US",
"9" : "Chicago - US",
"10" : "Cologne - DE",
"11" : "Johannesburg - ZA",
"12" : "Melbourne - AUS",
"13" : "Nagano - JP",
"14" : "Shanghai - CHN",
"15" : "Chennai - IN",
"16" : "Rio de Janeiro - BR",
"17" : "Stockholm - SWE",
"18" : "Paris - FR",
"19" : "Virginia - US",
"20" : "Ireland - IE",
"21" : "Hong Kong - HK",
"22" : "Sao Paulo - BR",
"23" : "Barcelona - ES",
"24" : "Milano - IT",
"25" : "New York - US",
"26" : "Los Angeles - US",
"27" : "Denver - US",
"28" : "Kansas - US",
"29" : "Munich - DE",
"30" : "Washington - US",
"31" : "Montreal - CA",
"32" : "Phoenix - US",
"33" : "Mumbai - IN",
"34" : "Istanbul - TR",
"35" : "Tel Aviv - IL",
"36" : "Sydney - AUS",
"37" : "Auckland - NZ",
"38" : "Atlanta - US",
"39" : "Brussels - BE",
"40" : "Toronto - CA",
"41" : "Copenhagen - DA",
"42" : "Vienna - AT",
"43" : "Zurich - CH",
"44" : "Warsaw - PL",
"45" : "Bucharest - RO",
"46" : "Moscow - RU",
"47" : "Beijing - CHN",
"48" : "Hangzhou City - CHN",
"49" : "Qingdao City - CHN",
"50" : "Miami - US",
"52" : "Tokyo - JP",
"55" : "Dubai - UAE",
"56" : "Queretaro - MEX",
"57" : "Falkenstein - DE",
"58" : "Strasbourg - FR",
"59" : "Bengaluru - IN",
"source" : "site24"
}

The fields name are not static and they can grow in the future.

If in the class I only map the ones that are static
class LocationInfo(Frame):
_collection = 'locations_info'
_fields = {
'source'
}

Than I've got only them in the query result
{'_document': {'_id': 'locations_names', 'source': 'site24'}}

Thanks

@anthonyjb
Copy link
Member

Hi @njordr - Have you looked at the Frameless snippet? That's one option, if you implement a Frameless class then there are no restrictions on the fields you can define.

Alternatively you can structure you document like so:

{
    "source": "site24",
    "locations": {
        "1" : "California - US",
        "2" : "New Jersey - US",
        ...
    }
}

Here locations become an embedded document instead.

@njordr
Copy link
Author

njordr commented Jul 11, 2016

Great, thanks for the frameless, i didn't see it :)

@njordr njordr closed this as completed Jul 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants