Apply projection to a document, returning `nodedb_types::Value`.
(doc: &Value, doc_id: &str, projection: &[String])
| 327 | |
| 328 | /// Apply projection to a document, returning `nodedb_types::Value`. |
| 329 | fn project_doc(doc: &Value, doc_id: &str, projection: &[String]) -> Value { |
| 330 | if projection.is_empty() { |
| 331 | // Add id if not present. |
| 332 | if let Value::Object(mut map) = doc.clone() { |
| 333 | map.entry("id".to_string()) |
| 334 | .or_insert(Value::String(doc_id.to_string())); |
| 335 | Value::Object(map) |
| 336 | } else { |
| 337 | doc.clone() |
| 338 | } |
| 339 | } else { |
| 340 | let mut map = std::collections::HashMap::new(); |
| 341 | map.insert("id".to_string(), Value::String(doc_id.to_string())); |
| 342 | for col in projection { |
| 343 | if let Some(v) = doc.get(col) { |
| 344 | map.insert(col.clone(), v.clone()); |
| 345 | } |
| 346 | } |
| 347 | Value::Object(map) |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | /// Expand a bounding box by a distance in meters. |
| 352 | fn expand_bbox(bbox: &nodedb_types::BoundingBox, meters: f64) -> nodedb_types::BoundingBox { |