Mongodb Join on _id field from String to ObjectId

You can use $toObjectId aggregation from mongodb 4.0 which converts String id to ObjectId db.role.aggregate([ { “$lookup”: { “from”: “user”, “let”: { “userId”: “$_id” }, “pipeline”: [ { “$addFields”: { “userId”: { “$toObjectId”: “$userId” }}}, { “$match”: { “$expr”: { “$eq”: [ “$userId”, “$$userId” ] } } } ], “as”: “output” }} ]) Or you … Read more

What is the point of Lookup?

It’s a cross between an IGrouping and a dictionary. It lets you group items together by a key, but then access them via that key in an efficient manner (rather than just iterating over them all, which is what GroupBy lets you do). For example, you could take a load of .NET types and build … Read more

How to get the Country according to a certain IP? [duplicate]

There are two approaches: using an Internet service and using some kind of local list (perhaps wrapped in a library). What you want will depend on what you are building. For services: http://www.hostip.info/use.html (as mentioned by Mark) http://www.team-cymru.org/Services/ip-to-asn.html For lists: http://www.maxmind.com/app/geoip_country (as mentioned by Orion) You could roll your own by downloading the lists from … Read more

Decision between storing lookup table id’s or pure data

You can use a lookup table with a VARCHAR primary key, and your main data table uses a FOREIGN KEY on its column, with cascading updates. CREATE TABLE ColorLookup ( color VARCHAR(20) PRIMARY KEY ); CREATE TABLE ItemsWithColors ( …other columns…, color VARCHAR(20), FOREIGN KEY (color) REFERENCES ColorLookup(color) ON UPDATE CASCADE ON DELETE SET NULL … Read more

How can I lookup a Java enum from its String value?

Use the valueOf method which is automatically created for each Enum. Verbosity.valueOf(“BRIEF”) == Verbosity.BRIEF For arbitrary values start with: public static Verbosity findByAbbr(String abbr){ for(Verbosity v : values()){ if( v.abbr().equals(abbr)){ return v; } } return null; } Only move on later to Map implementation if your profiler tells you to. I know it’s iterating over … Read more

How to do vlookup and fill down (like in Excel) in R?

If I understand your question correctly, here are four methods to do the equivalent of Excel’s VLOOKUP and fill down using R: # load sample data from Q hous <- read.table(header = TRUE, stringsAsFactors = FALSE, text=”HouseType HouseTypeNo Semi 1 Single 2 Row 3 Single 2 Apartment 4 Apartment 4 Row 3″) # create a … Read more