diff --git a/food-tracking/scripts/food_items.py b/food-tracking/scripts/food_items.py index 1724ade..d67cc85 100644 --- a/food-tracking/scripts/food_items.py +++ b/food-tracking/scripts/food_items.py @@ -51,10 +51,19 @@ def cmd_get(args): coll, client = get_collection() query = {} if args.name: - query["$or"] = [ - {"name": {"$regex": args.name, "$options": "i"}}, - {"aliases": {"$regex": args.name, "$options": "i"}}, - ] + # Try exact match first (name or any alias), then regex fallback + name_lower = args.name.lower() + exact = coll.find_one({"$or": [ + {"name": name_lower}, + {"aliases": name_lower}, + ]}) + if exact: + query["_id"] = exact["_id"] + else: + query["$or"] = [ + {"name": {"$regex": args.name, "$options": "i"}}, + {"aliases": {"$regex": args.name, "$options": "i"}}, + ] if args.type: query["type"] = {"$regex": args.type, "$options": "i"}